CentOS7 upgrade python3

CentOS7 upgrade python3 process and attention#

Check the current version
[ root@node1 ~]# python -V
Python 2.7.5
Create installation directory (custom)
[ root@node1 Python-3.7.1]# mkdir /usr/local/python3

Download the python3 compressed package from the official website, unzip it (with 3.7.1 version as an example)
# wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
# tar zxf Python-3.7.1.tgz 

cd into the unzipped directory, then
# cd Python-3.7.1
# . /configure --prefix=/usr/local/python3/
# make && make install

cd enter/usr/bin
Among them are python, python2, python2.7 The three files point to the latter in turn.
Back up the current default version of python, and restore it if necessary:
# sudo mv python python.bak

Create python3.7 new link (you can also create a python3 command to distinguish, same as mac), so the default python version is replaced with python3.7
# ln -s /usr/local/python3/bin/python3.7/usr/bin/python

Check the current default python version
# python -v

Since yum uses python2, it cannot work normally after replacing it with python3.
So modify the yum configuration file:
# sudo vi /usr/bin/yum
Change the python version specified in the first line to python2.7:*#!/usr/bin/python to#!/usr/bin/python2.7

Modify the urlgrabber configuration file (many online tutorials miss this step)
# sudo vi /usr/libexec/urlgrabber-ext-down
Same as yum, change the python of the head to python2.7

Link: https://www.jianshu.com/p/74227d7ae6a6

problem#

After Python is installed, it prompts that the ssl module cannot be found:

(< http://blog.csdn.net/qq_25560423/article/details/62055497>;)

For example:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 

Collecting xxx 

Could not fetch URL <https://pypi.python.org/simple/xxxx/>: 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 xxx(from versions:) 

No matching distribution found for xxx

[ root@localhost ~]# python2.7.5

Python 2.7.5 (default, Jun 3 2013, 11:08:43)

[ GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

import ssl
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/python27/lib/python2.7/ssl.py”, line 60, in
import _ssl # if we can’t import it, let the error propagate
ImportError: No module named _ssl


  1. Check the openssl installation package and found that the openssl-devel package is missing
    [ root@localhost ~]# rpm -aq|grep openssl
    openssl-0.9.8e-20.el5
    openssl-0.9.8e-20.el5
    [ root@localhost ~]#

  2. yum install openssl-devel
    [ root@localhost ~]# yum install openssl-devel -y
    View installation results
    [ root@localhost ~]# rpm -aq|grep openssl
    openssl-0.9.8e-26.el5_9.1
    openssl-0.9.8e-26.el5_9.1
    openssl-devel-0.9.8e-26.el5_9.1
    openssl-devel-0.9.8e-26.el5_9.1

  3. Recompile python
    Modify the Setup file
    vi /usr/software/Python-2.7.5/Modules/Setup
    Amend to the following:

Socket module helper forsocket(2)

_ socket socketmodule.c timemodule.c

Socket module helper for SSL support; you must comment out the other

socket line above, and possibly edit the SSL variable:

SSL=/usr/local/ssl

_ ssl _ssl.c \

- DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \

- L$(SSL)/lib -lssl -lcrypto
  1. Recompile
    make
    make install

  2. Tested, it can be used normally.
    [ root@localhost ~]# python2.7.5
    Python 2.7.5 (default, Jun 3 2013, 14:56:13)
    [ GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
    Type “help”, “copyright”, “credits” or “license” for more information.
    import ssl

Reinstall with pip

Recommended Posts

CentOS7 upgrade python3
Centos 6.4 python 2.6 upgrade to 2.7
Centos 6.4 python 2.6 upgrade to 2.7
CentOS + Python3.6+
Centos 7.5 python3.6
Centos default python2.6 upgrade to
CentOS upgrade python2 to pyth
Centos6 install Python2.7.13
Ubuntu16 upgrade Python3
Centos7 install Python 3.6.
CentOS install Python 3.6
Python - centos6 installation
Centos7 install Python2.7
Centos6.5 openssh upgrade
Centos6.7 comes with python upgrade to
Centos install Python3
Centos7 upgrade kernel
CentOS6.8 install python2.7
centos6.9 rabbitmq 3.6.8 upgrade 3.8.2
ubuntu16.04 upgrade python2
Centos python3 compile installation and compile gcc upgrade
CentOS7.5-1804 system kernel upgrade
Centos source installation Python3
CentOS6.5 upgrade kernel to 3.10.28
Centos kernel version upgrade
CentOS Python Java installations
centos7 install python3 and ipython
CentOS 8 (2)
Centos 6.10 reinstall python and yum
CentOS7 install python3 and pip3
CentOS 8 (1)
CentOS 6.9 compile and install python
Centos6 install python3 pip3 ipython3
CentOS 6 compile and install python 3
centos6.5: gcc upgrade (5.2.0) process record
Centos7 deploys python3 virtual environment
How to upgrade CentOS7 to CentOS8 (detailed steps)
Three methods of Centos kernel upgrade
Upgrade OpenSSL and OpenSSH under CentOS7
Centos7 upgrade git version control tool
CentOS quickly install Python3 and pip3
How to install Python 3.8 on CentOS 8
Linux: Centos7 upgrade the original kernel
How to install Python on CentOS 8
Install Python3 and ansible under CentOS8
Configure python3 environment on centos7 and
Remember a centos 7 kernel upgrade accident
Install Python3 and Py under CentOS7
Manually upgrade node version under CentOs
Manually upgrade node version under CentOs
CentOS7 repairs python to save yum
CentOS 7 configure Python language development environment
Python multithreading
Python CookBook
Python3 dictionary
Python3 module
python (you-get)
centos7 python3.7+vi
Python string
Python basics
Python descriptor