1、下載python3.5
wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
註:如果在Linux中下載較慢,可以在Windows作業系統中去Python官網下載:https://www.python.org/downloads/release/python-350/
注意要下載Gzipped source tarball版本的,然後使用WinSCP將下載好的檔案Python-3.5.0.tgz拖拽到Linux中,後續步驟還是不變的。
2、解壓
tar zxvf Python-3.5.0.tgz
3、進入Python-3.5.0檔案夾
cd Python-3.5.0
4、配置安裝位置
./configure --prefix=/usr/local/python3.5
註:如果沒有安裝C語言編譯器會提示錯誤。如果出現錯誤,在連網的情況下使用 yum install gcc 命令安裝gcc編譯器
5、編譯
make
6、安裝
make install
7、下載並安裝setuptools 18.5
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
註:如果提示錯誤 --no-check-certificate
在wget後加上 --no-check-certificate :wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | python
8、備份原有python命令執行檔案
mv /usr/bin/python /usr/bin/pythonbak
9、建立新python軟串連
ln -s /usr/local/python3.5/bin/python3.5 /usr/bin/python
10、查看python版本
python
[root@localhost Python-3.5.0]# pythonPython 3.5.0 (default, Oct 7 2016, 04:34:35) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linuxType "help", "copyright", "credits" or "license" for more information.
11、修改yum設定檔
vim /usr/bin/yum
#!/usr/bin/python python修改為 python2.6import systry: import yumexcept ImportError: print >> sys.stderr, """\There was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was: %sPlease install a package which provides this module, orverify that the module is installed correctly.It's possible that the above module doesn't match thecurrent version of Python, which is:%sIf you cannot solve this problem yourself, please go to the yum faq at: