After linux centos7, it is necessary to upgrade python2.7 to python3 installation. Because most applications still use pytho3.6. In centos, 2.7 yum should be reserved.
Old python version: 2.7.5
New python version: 3.6.8 Less
talk, start:
Please install openssl before starting to install python3. Otherwise, verification error occurs when pip3 installs virtualenv.
yum install openssl openssl-devel
-
From the Python official website to get the Python3 package, switch to the directory / usr / local / src and
execute the command line:wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
-
Use the command, the following command to decompress:
tar -xzf Python3.6.8.tgz
-
Create a directory under the / usr / local path – python3
mkdir /usr/local/python3
-
Compile and install
A. Execute command:cd /usr/local/src/Python-3.6.8
B. Execute command:./configure --prefix=/usr/local/python3
C. Execute command:make all
D. Execute the command:
make install
-
Enter the absolute path of the installation and check whether the installation is successful.
Run the command:/usr/local/python3/bin/python3.6 -V
-
Check the environment variables, and search by default in the order of PATH when starting python.
Excuting an order:echo $PATH
-
Modify the soft connection, point to python3.6 when starting python
A. Python
execute command before backup : mv / usr / bin / python /usr/bin/python2.7.5 (please check your own python version first)
B. Modify the soft connection
Execute command: ln -s / usr / local / python3 / bin / python3 / usr / bin / python
C. View python version:
execute command:python
-
In order to input only when it is convenient, you can add alias
A. execute command:cd ~
B. execute command:cat .bashrc
C. execute command:source .bashrc
-
Check whether python3 is started by default to
execute the command:python3 -V
-
Modify the yum file, because after upgrading the version, yum will report an error:
execute the command:sudo vim /usr/bin/yum
follow the old version number after the first line!
-
Next, an error will be reported when installing the software:
Solution:
Execute the command:sudo vim /usr/libexec/urlgrabber-ext-down
In the first line of the file, also change to python2.7 (2.7 is the version, change it according to your own version!) -
Related pip3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
check version
pip3 -V
Note that pip3 is included when compiling python3. If not, please use make when compiling python3
-
Use pip3 to install virtualenv.
Before using pip3 to install virtualenv, first install openssl. Otherwise, it will prompt an error. After
yum install openssl openssl-devel
installing openssl and recompiling python3, install virtualenv.
pip3 install virtualenv
-
Also, if there is a garbled situation when pressing the backspace key (or arrow keys),
yum install readline-devel readline
then recompile.