Centos6 安裝Python3.6及設置對應版本pip的簡單方式

Python3其中已經是默認安裝了pip及setuptools,所以安裝完Python後創建pip3對應的軟鏈接,就可以使用 pip install xxx,網上太多的教程重複安裝了pip。部分文章按安裝Python2的安裝方式寫了 Python3 的安裝方式,比如安裝setuptools等,反而容易出現了各種問題。

 

1.提前安裝需要的環境

yum install openssl-devel
yum install zlib-devel

2.安裝Python3.6

從官網上wget python3.6安裝包:

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz

解壓

tar -xvf Python-3.6.0.tar.xz

設置安裝路徑

cd Python-3.6.0
./configure --prefix=/usr/local/python3

編譯安裝

make && make install

3.建立Python3.6和pip3的軟鏈接

mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

執行Python,看到提示的是3.6的版本。

執行安裝命令pip install xxx來安裝,pip install gevent,看到pip成功。

 

4.yum是依賴Python2的,因爲修改了 Python 軟鏈接,所以需要爲yum指定原來的Python版本,不然yum不可用。

執行 vi /usr/bin/yum

把#! /usr/bin/python修改爲#! /usr/bin/python2.6 ,即系統原來的Python版本。

 

5.錯誤問題:

[root@localhost Python-3.6.0]# python -m pip install gevent
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting gevent
  Could not fetch URL https://pypi.python.org/simple/gevent/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement gevent (from versions: )
No matching distribution found for gevent

這個報錯說明缺少openssl的開發環境,yum install openssl-devel 沒有成功,需要再次執行,然後在進入Python文件夾 ,執行 make && make install 再次編譯Python。

 

 

RuntimeError: Compression requires the (missing) zlib module

zlib-devel包沒有安裝成功,需要再次執行 yum install zlib-devel ,然後在進入Python ,執行 make && make install 再次編譯Python。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章