1. Application scenarios
The Python2 that comes with Linux is still intact, and another set of Python3 programming is used. yum still uses Python2;
2. Software packages to be prepared
These three compressed files can be placed in the same directory (such as the home directory~)
Python-3.5.2.tgz
pip-8.1.2.tar.gz
setuptools-24.0.2.tar.gz
3. Unzip and install
(1) Unzip Python-3.5.2.tgz
解压:tar -zxvf Python-3.5.2.tgz
进入解压目录: cd Python-3.5.2
创建安装目录: mkdir /usr/local/python3.5.2
编译: ./configure prefix=/usr/local/python3.5.2
安装: make && make install
创建软链接:ln -s /usr/local/python3.5.2/bin/python3.5 /usr/bin/python3
The above steps are generally not wrong, but there will be some errors when installing pip3, which should be noted.
(2) Unzip and install setuptools-24.0.2.tar.gz
tar -zxvf setuptools-24.0.2.tar.gz
cd setuptools-24.0.2
python3 setup.py install
At this point, a RuntimeError: Compression requires the (missing) zlib module error will appear.
The solution is to enter the Python installation package and recompile once:
yum install zlib-devel
cd Python-3.5.2
make && make install
cd setuptools-24.0.2
python3 setup.py install
(3) Unzip and install pip-8.1.2.tar.gz
tar -zxvf pip-8.1.2.tar.gz
cd pip-8.1.2
python3 setup.py install
At this point, ImportError: cannot import name HTTPSHandle error will appear
Solution
yum -y install openssl openssl-devel
cd Python-3.5.2
make && make install
cd pip-8.1.2
python3 setup.py install
建立软链接:ln -s /usr/local/python3.5.2/bin/pip3 /usr/bin/pip3
Note: The order of steps 2 and 3 cannot be reversed, otherwise an error will be reported. Of course, it doesn't matter if you report an error. In the end, it will tell you to install setuptools first, and then install pip3.