Python3.6.5和pip安裝指令碼以及離線安裝pip包【原創】
阿新 • • 發佈:2020-08-28
1、將Python3.6.5安裝包及python36_install.sh放在同一目錄
# ll -thr-rw-r--r--. 1 root root 22M Aug 10 05:09 Python-3.6.5.tgz -rw-r--r--. 1 root root 1.2K Aug 10 20:58 python36_install.sh -rw-r--r--. 1 root root 71K Aug 28 04:50 redis-3.5.3-py2.py3-none-any.whl
安裝指令碼內容
# vim python36_install.sh
#!/bin/bash
#===============================================================================#
# FILE: python36_install.sh
#
# USAGE: install python36 script
#
# DESCRIPTION: To install python36 automatically
#
# BUGS: ---
# NOTES: ---
# AUTHOR: chh-huang
# CREATED: 04/13/2020 08:46:05 PM
# VERSION: 1.0
#=============================================================================== tar -vxf Python-3.6.5.tgzif [[ $? = 0 ]];then echo '' echo -e "\e[1;32mpython3.6 unzip success.\e[0m" cd Python-3.6.5 yum install gcc openssl openssl-devel ncurses-devel.x86_64 bzip2-devel sqlite-devel python-devel zlib -y if [[ $? = 0 ]];then echo -e "\e[1;32myum install success.\e[0m" ./configure --prefix=/usr/local/python3if [[ $? = 0 ]];then echo -e "\e[1;32mpython configure success.\e[0m" make if [[ $? = 0 ]];then echo -e "\e[1;32mpython make success.\e[0m" make install if [[ $? = 0 ]];then echo -e "\e[1;32mpython make install success.\e[0m" ln -sv /usr/local/python3/bin/python3 /usr/bin/python3 ln -sv /usr/local/python3/bin/pip3 /usr/bin/pip3 echo -e "\e[1;32mpython3.6 install success.\e[0m" python3 else echo -e "\e[1;31mpython3.6 make install failed.\e[0m" exit fi else echo -e "\e[1;31mpython make failed.\e[0m" exit fi else echo -e "\e[1;31mpython configure failed.\e[0m" exit fi else echo -e "\e[1;31m2yum install failed.\e[0m" exit fi else echo '' echo -e "\e[1;31mpython3.6 unzip failed.\e[0m" exit fi
2、執行指令碼
sh python36_install.sh
3、會自動安裝好Python和pip,並做成軟連結,與現有Python不衝突
4、離線安裝pip包
有的生產系統伺服器不允許連線內網,所以要用離線方法安裝
先在能上網伺服器下載
pip3 install redis --download /tmp
# 下載後的檔案以whl字尾的檔案,在/tmp目錄
-rw-r--r-- 1 root root 71K 8月 28 16:30 redis-3.5.3-py2.py3-none-any.whl
將檔案拷貝到伺服器上安裝,將檔案放到/root目錄下
# pip3 install --no-index --find-links="/root" redis
Collecting redis
Installing collected packages: redis
Successfully installed redis-3.5.3
訪問試試
# python3 Python 3.6.5 (default, Aug 28 2020, 17:11:02) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import redis >>>
轉載請註明出處!!!