升級centos6內建的python2.6版本至python2.75

來源:互聯網
上載者:User

標籤:hosted   src   set   rom   pytho   oca   cal   內建   修改   

背景: 

  在部署flask程式時,用到了SQLAlchemy,要求最低是python2.7版本的環境才可以,所以決定升級python版本,由此引發了一系列的問題。

環境:

  CentOS release 6.9 (Final)
  Python 2.6.6

開幹:

  參考文檔:https://www.cnblogs.com/smileyes/p/7288487.html

下載軟體包

  wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz

解壓

  tar -xzvf Python-2.7.15.tgz

配置編譯安裝

  ./configure --prefix=/usr/local/python2&&make&&make install

使用新的python

  rm -rf /usr/bin/python

  ln -s /usr/local/python2/bin/python /usr/bin/python

 

遇到的問題:

  1、python升級,原有pip不能使用 

  2、python升級,yum不能使用

解決

1、python版本升級對應的pip版本也需要升級,否則會有問題。這裡需要用到setup-tools。

wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gzwget https://files.pythonhosted.org/packages/a9/23/720c7558ba6ad3e0f5ad01e0d6ea2288b486da32f053c73e259f7c392042/setuptools-36.0.1.zip
解壓
tar xvf pip-9.0.1.tar.gzunzip setup-tools-36.0.1.zip
安裝setup-tools
cd setup-tools-36.0.1python setup.py install
安裝pip
cd pip-9.0.1
python setup.py install
使用新的pip
ln -s /usr/local/python2/bin/pip /usr/bin/pip
pip -V
pip 9.0.1 from /usr/local/python2/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)

 

2、yum無法正常使用

 

修改yum命令,將首行解譯器指定為舊的python2.6即可解決

vim /usr/bin/yum

#!/usr/bin/python2.6

 

完工,繼續之後的flask程式部署動作,pip -r requirment.txt自動安裝所需要的包。

升級centos6內建的python2.6版本至python2.75

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.