Install python3 in centos7

Keywords: pip SSL Python yum

1. Install the corresponding compilation tools

In the root user (do not use ordinary users, trouble), all copy and paste in the past, a one-time installation

yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install -y libffi-devel zlib1g-dev
yum install zlib* -y

2. Download the installation package

wget wget

3. Decompress

tar -xvJf  Python-3.7.2.tar.xz

4. Create compilation and installation directory

mkdir /usr/local/python3 

5. Installation

cd Python-3.7.2
./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl 
#The first is to specify the installation path. If not specified, the files required by the software may be copied to different directories during the installation process. It is inconvenient to delete the software and copy the software
#The second one can improve the running speed of Python 10% - 20%
#The third is to install pip using ssl, which will be mentioned later
make && make install


6. Create soft link

ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

7. Verify success

python3 -V
pip3 -V

8. Error reporting

Error 1

zipimport.ZipImportError: can't decompress data; zlib not available Makefile:1099: recipe for target 'install' failed make: *** [install] Error 1

Installation dependency required

yum -y install zlib1g-dev

Error 2

ModuleNotFoundError: No module named '_ctypes'

Installation dependency required

yum -y install libffi-devel 

The dependencies required by these two errors have been added to the initial dependency installation
Reference article

9. Install pipenv

Using Python 3.7 or above in centos makes pip install command easy to report errors

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https:*******: There was a problem confirming the ssl certificate: 
Can't connect to HTTPS URL because the SSL module is not available. - skipping

During. / configure, if the – with ssl parameter is not added, the function of ssl related to the default installed software is not available, just because the pip3 process requires the ssl module, but because it is not specified, the function is not available. The solution is to recompile and install python3.6. Use the following procedure to implement the compilation and installation:

cd Python-3.7.2
./configure --with-ssl
make && make install

The pip can be installed normally
This is also specified when installing python
Reference article

10. Modify pip installation source

Modify system pip installation source
Create a new. PIP folder in the home directory and enter the folder to create a new file pip.conf Then write the corresponding mirror website address

cd ~
mkdir .pip
cd .pip
vim pip.conf

#After entering, add the following content and save to exit
index-url =

Modifying the pipenv installation source
Find the Pipfile file in your own virtual environment, and put the URL in it =“ "Change to the domestic image you need, such as

[root@localhost myproject]# vim Pipfile 

name = "pypi"
url = " "Change to url =" "
verify_ssl = true

[dev-packages] #Here is the development environment specific package. Use pipenv install --dev package to install the development environment specific package

[packages] # General package for all environments, installed here

python_version = "3.7"

Posted by guido88 on Thu, 18 Jun 2020 20:12:07 -0700