wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgzpython
想下載到那個文件夾下就先進入到那個文件夾下——cd /home/downloadlinux
tar -xvf Python-3.6.0.tgzvim
mkdir /usr/local/python3centos
進入到解壓目錄下緩存
./configure --prefix=/usr/local/python3ruby
一、makebash
二、make installsocket
make install 報錯:zipimport.ZipImportError: can’t decompress data測試
a、打開終端,輸入一下命令安裝zlib相關依賴包:ui
yum -y install zlib*
redhat 配置yum源:
進入到 /etc/yum.repos.d, 其中有個rhel-source.repo, 先更名爲rhel-source.repo.bak,作個備份
而後新建個 rhel-source.repo
[updates] name=CentOS-6 - Updates - 163.com baseurl=http://mirrors.163.com/centos/6/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-6 - Extras - 163.com baseurl=http://mirrors.163.com/centos/6/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
清理並重建緩存
yum clean all
yum makecache
更新yum
yum update
b、進入 python安裝包,修改Module路徑的setup文件:
vim Module/Setup
找到一下一行代碼,去掉註釋:
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz 去掉註釋 zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
從新安裝
三、完畢
一、修改舊版本
mv /usr/bin/python /usr/bin/python_bak
二、建立新的軟鏈接
ln -s /usr/local/python3/bin/python3 /usr/bin/python
三、檢查python的版本
python -V
python-3.6.0
軟鏈接建立成功
一、export PATH=$PATH:$HOME/bin:
二、export PATH=$PATH:$HOME/bin:/usr/local/python3/bin
三、完成
這時pip3就可使用了。
注:升級完成後,yum沒法使用,需更改yum指向源2.7版本
vim /usr/bin/yum,第一句更改成原版本路徑便可
後續問題:
pip3安裝包時報錯,pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
解決方案:
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python3/lib/python3.6/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>>
2. 查看openssl安裝包,發現缺乏openssl-devel包
[root@localhost ~]# rpm -aq|grep openssl
openssl-1.0.1e-57.el6.x86_64
3. yum安裝openssl-devel
[root@localhost ~]# yum install openssl-devel -y
#查看安裝結果
[root@localhost ~]# rpm -aq|grep openssl
openssl-1.0.1e-57.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64
4. 從新編譯python
#修改Setup文件
vi /usr/software/Python-2.7.5/Modules/Setup
#修改結果以下:
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
5. 從新編譯
make
make install
6. 測試,已可正常使用。[root@localhost ~]# pythonPython 3.6.0 (default, Jan 25 2018, 22:31:55) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import ssl>>>