下載並解壓:
1 wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz 2 tar -xzvf Python-3.7.2.tgz
進入目錄:
cd Python-3.7.2
編譯:
./configure --prefix=/usr/local/python3
安裝:
make
make insatll
缺少依賴包導致:
執行:yum -y install zlib* 安裝依賴包即可
仍缺少組件,無法導入_ctypes模塊:
1 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel 2 yum install libffi-devel -y
https://cpython-devguide.readthedocs.io/setup/#build-dependencies
注意:此步驟安裝完成之后,需要重新編譯文件
安裝完成之后,python已經安裝成功,但是需要配置環境變量,(如果不想配置環境變量可以在編譯那一步將 --prefix=/usr/local/python3 這一部分去掉【沒有測試】
)
創建軟連接即可,
1 [root@bing ~]# mv /usr/bin/python /usr/bin/python_bak 2 [root@bing ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python 3 [root@bing ~]# python 4 Python 3.7.2 (default, Feb 23 2019, 19:05:50) 5 [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux 6 Type "help", "copyright", "credits" or "license" for more information. 7 >>> exit()
pip還無法使用
1 [root@bing ~]# PATH=$PATH:$HOME/bin: 2 [root@bing ~]# PATH=$PATH:$HOME/bin:/usr/local/python3/bin
配置完環境變量(在本次會話中)即可使用pip,最好是創建軟連接
續;
安裝過程中出現:pip is configured with locations that require TLS/SSL, however the ssl modul
#重新編譯安裝 ./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl make make install #重新第三方庫pymysql pip3 intall pymysql