table of Contents
Install python3
Download the installation package, if it is slow, download and upload it locally, unzip tar zxvf Python-3.6.6.tgz
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
Download the dependency package compiled by python3
yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
cd Python-3.6.6
./configure --prefix=/opt/python36 # Specify the installation directory as /opt/python36
make # is equivalent to compiling the code in the source package into code that can be recognized by the linux server
The result of make is as follows
make install
Compile and install, this step will finally generate /opt/python36/ and the results are as follows
vi /etc/profile
加上 PATH=/opt/python36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/profile #Make the file effective
python3 check if the installation is successful
python2 switch python3
Switch as follows
mv /usr/bin/python /usr/bin/python.bak Delete the original soft link to python2
ln -s /opt/python36/bin/python3.6 /usr/bin/python
At this time, an error may be reported ln: failed to create symbolic link'/usr/bin/python': File exists
Solution: ln -sf /opt/python36/bin/python3.6 /usr/bin/python
After the installation is complete, enter python and you will see the version is 3
Install pip
python3 get-pip.py #Compile, specify python3, if you use python by default 2, you can enter the command python to check the current version
Linux defaults to python2, which will cause yum not to be used after switching
报错:File "/usr/bin/yum", line 30
except KeyboardInterrupt, e
Solution:
vi /usr/libexec/urlgrabber-ext-down after the first line is changed to python2 to save
If you still report a similar error, then change the corresponding file as the first line python2.
Because the server still depends on python2, it is best not to move if it is not a great god
Just execute it again after the change
View version: pip -V