Linux下系统默认一般自带Python,只不过带的是Python2,至于是Python2点几,就要看linux系统的版本了,一般是Python2.6或者Python2.7。那么,如果想要安装Python3应该怎么办呢? 很简单,其实Linux下是同时支持Python2以及Python3的。因此,只需要根据自己的情况来安装相应版本的Python3就可以了。记住一点,千万不要卸载系统自带的Python2(如果你想挑战一下自己,可以试试,我不建议),亲身经历,切肤之痛。下面就根据自己的安装经验说说应该如何安装Python3,以及安装过程中出现的问题。
一、python3安装过程:
1,到官网下载Linux版本的Python3
附上链接地址,Python3官网下载地址
2,上传(Windows下载的话,可以用FileZilla上传),建议放到/usr/local/目录下,解压。
3,进入到解压之后的路径,配置安装目录,并编译、安装。
进入解压后文件目录:
配置安装目录:
编译:
安装:
4,建立Python3的软连接
5,此时,基本上已经安装完毕,试一下在命令行输入python3。
6,centOS安装时报了一个错,如下:
Configure:error:no acceptable compiler found in$PATH
此时,需要安装gcc
yum install gcc
./configure --prefix=/usr/local/python3
二、安装setuptools:
1,到官网下载setuptools安装包,找到自己需要的版本
附上链接地址:setuptools官网
2,上传(Windows下载的话,可以用FileZilla上传),建议放到/usr/local/目录下,解压。
cd /usr/local
tar -zxvf setuptools-31.0.1.tar.gz
3,编译并安装
cd setuptools-31.0.1
python3 setup.py build
python3 setup.py install
4,如果,此时没问题的话,恭喜你如此之快就成功了。假如不小心报了以下的错误,那么也不用担心!
报错信息如下:
File"/usr/local/python26/lib/python2.6/zipfile.py",line 732,in __init__
"Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module
对此,我们需要安装zlib以及zlib-devel
yum install -y zlib
yum install -y zlib-devel
安装完成之后,需要对python3进行重新编译安装
cd /usr/local/Python3.6.5rcl
make & make install
经过漫长的等待之后,就可以重新安装setuptools了
cd setuptools-31.0.1
python3 setup.py build
python3 setup.py install
至此,就可以大功靠成了
三、安装pip
1,到官网下载pip安装包,找到自己需要的版本
附上链接地址:pip官网
2,上传(Windows下载的话,可以用FileZilla上传),建议放到/usr/local/目录下,解压。
cd /usr/local
tar -zxvf pip-10.0.1.tar.gz
3,编译并安装
cd /pip.10.0.1
python3 setup.py install
4,如果,此时没问题的话,恭喜你如此之快就成功了。假如不小心报了以下的错误,那么也不用担心。
报错信息如下:
pip is configured with locations that require TLS/SSL,however the ssl module in python is not available
或者:
- Could not fetch URL https://pypi.python.org/simple/bottle/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
此时,在Python3里面import ssl,就会报错。因此,需要安装openssl以及openssl-devel包
yum install openssl
yum install -y openssl-devel
修改Modules/Setup(该目录在解压路径之下)
vim Modules/Setup
找到以下内容修改如下:
然后,重新编译安装Python即可解决