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。

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