CentOS下Python2.6升級到Python3.5__Python

來源:互聯網
上載者:User

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:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.