Debian Python升級+pip安裝——基礎環境配置

來源:互聯網
上載者:User

標籤:

第一步:下載python2.7.9版本源碼:

wget http://python.org/ftp/python/2.7.9/Python-2.7.9.tgz

解壓檔案

#tar zxvf Python-2.7.9.tar.bz2[email protected]:/opt/software# cd Python-2.7.9/[email protected]:/opt/software/Python-2.7.9# dirconfig.guess  Doc         LICENSE          Objects        Pythonconfig.sub    Grammar     Mac              Parser         READMEconfigure     Include     Makefile.pre.in  PC             RISCOSconfigure.ac  install-sh  Misc             PCbuild        setup.pyDemo          Lib         Modules          pyconfig.h.in  Tools[email protected]:/opt/software/Python-2.7.9# mkdir /usr/local/python2.7.9

 

編譯之前,需要先安裝zlib包:

從官網http://www.zlib.net/下載zlib-1.2.8.tar.gz

[email protected]:/opt/software# tar -xvf zlib-1.2.8.tar.gz[email protected]:/opt/software# cd zlib-1.2.8[email protected]:/opt/software# ./configure && make && make install

 

進入Python-2.7.9目錄,開始安裝Python

[email protected]:/opt/software/Python-2.7.9# ./configure --prefix=/usr/local/python2.7.9[email protected]:/opt/software/Python-2.7.9# make && make install

 

安裝成功!

[email protected]:/opt/software/Python-2.7.9# python -VPython 2.6.6

版本依然是2.6.6,現在開始升級python,

查看python命令所在目錄

[email protected]:/opt/software/Python-2.7.9# whereis pythonpython: /usr/bin/python2.6 /usr/bin/python /etc/python2.6 /etc/python /usr/lib/python2.6 /usr/lib/python2.4 /usr/lib/python2.5 /usr/local/lib/python2.6 /usr/include/python2.6 /usr/share/python /usr/share/man/man1/python.1.gz

 

將/usr/bin/python備份

[email protected]:/opt/software/Python-2.7.9# mv /usr/bin/python /usr/bin/python2.6.6
[email protected]:/opt/software/Python-2.7.9# python-bash: /usr/bin/python: No such file or directory

 

python命令找不到,這時只需要將版本python2.7.9命令加入環境變數即可!

方式1:

修改/etc/profile加入如下兩行:

PATH=$PATH:/usr/local/python2.7.9/binexport PATH

然後

[[email protected] Python-2.7.9]# source /etc/profile[[email protected] Python-2.7.9]# python -VPython 2.7.9

 

當然也可以建立2.7.9版本的python的軟串連:/usr/bin/python

[[email protected] ~]# ln -s /usr/local/python2.7.9/bin/python2.7 /usr/bin/python

 

亦可

ok,python升級完成

 

但運行python get-pip.py時,報錯,原因是 python沒有完整安裝好,缺少ssl模組

修改 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

 

重新編譯

make && make install

 

又報錯:ssl錯誤,原因是openssl-devel未安裝

使用:

apt-get install opensslapt-get install libdev-ssl

再次編譯,搞定

 

第二步、安裝pip  參見https://pip.pypa.io/en/latest/installing.html

To install pip, securely download get-pip.py. [2]

Then run the following (which may require administrator access):

python get-pip.py

pip被預設安裝在:/usr/local/python2.7.9/bin/

 

 此時要注意pip版本的問題,之前的/usr/bin/pip可能是使用 apt-get install python-pip安裝上的,

將/usr/bin/pip 升級為/usr/local/python2.7.9/bin/pip2.7:

ln -s /usr/local/python2.7.9/bin/pip2.7  /usr/bin/pip

 Ok,至此 pip安裝環境構建成功!

 

第三步、安裝python Django運行必須包 [可選]

1、安裝MySQLdb

官網下載MySQL-python-1.2.3.tar.gz,解壓安裝

# python setup.py install

 

2、安裝pillow

#pip install pillow

3、安裝uwsgi [可選]

#pip install uwsgi

建立軟連結:

# ln -s /usr/local/python2.7.9/bin/uwsgi /usr/bin/uwsgi

 



 

 



 

Debian Python升級+pip安裝——基礎環境配置

相關文章

聯繫我們

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