Installation and pit avoidance guide of Python 3.6 under Linux


Installation of Python 3

1. Installation dependent environment

Various dependency libraries may be used in the installation process of Python 3, so these dependency libraries need to be installed before the formal installation of Python 3.

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

2. Download the python 3 source code

There are two ways to download the source code of Python 3. One is to download it from its official website at the following address:


Another way is to download directly through WGet, such as the following command:


3. Create installation directory

The installation directory can be created according to personal preference. For example, the installation directory can be created here/usr/local/python3

mkdir -p /usr/local/python3

4. Unzip the source code package

Unzip the source code package downloaded in step 2. The command is:

tar -zxvf Python-3.6.1.tgz

5. Compile the source code

First enter the directory of the decompressed source package, and then configure it

cd Python-3.6.1
./configure --prefix=/usr/local/python3

Then compile and install:

make install

6. Build the soft link of Python 3

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

7. Add / usr / local / python3 / bin to path

Edit Bash_ Profile to modify environment variables:

vim ~/.bash_profile

Add the startup directory of Python 3 in the path variable

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc

# User specific environment and startup programs


export PATH

After changing, press ESC, and then enter: WQ to save and exit.

8. Check whether python3 and PIP3 are available

Execute the following command (Note: V is uppercase V). If the results are consistent, it means that Python 3 has been successfully installed.

[[email protected]_0_16_centos ~]$ python3 -V
Python 3.6.1
[[email protected]_0_16_centos ~]$ pip3 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

Pit avoidance Guide

In fact, for the installation of Python 3, there are too many posts on the network, and the steps are almost the same. However, in the real hands after the installation, more or less will encounter some trouble, especially for novices. Here are some common pits:

Configuration: error: no acceptable C compiler found in $path

This problem is relatively simple, that is, the lack of GCC compilation environment. Just install GCC

yum install -y gcc

Of course, in addition, the source code installation method can also be used.

Pit 2: zipimport.ZipImportError : can’t decompress data

This problem is caused by the lack of zlib’s related toolkits

yum -y install zlib*

After installation, recompile the source code to solve the problem.

PIP3: can’t connect to HTTPS URL because the SSL module is not available

This problem is because in the. / configure process, if the – with SSL parameter is not added, the SSL function of the software installed by default is not available. It just happens that the PIP3 process needs SSL module, but this function is not available because it is not specified. The solution is as follows:

cd Python-3.6.2
./configure --with-ssl
sudo make install

Pit 4: multilib version problems

It’s obvious that there are multiple versions of the same library. Just delete the redundant version.

First, query the existing version (take OpenSSL as an example, check which version conflicts with which version)

# rpm -qa | grep openssl

You can see that openssl-1.0.0-27.el6 is installed in the system_ 4.2.x86_ 64 and openssl-1.0.0-27.el6_ 4.2.i686 two versions of OpenSSL, we can leave the x86 version:

rpm --erase --nodeps openssl-1.0.0-27.el6_4.2.i686

Update OpenSSL again

# yum update "openssl*"

Query OpenSSL again, problem solved!

# rpm -qa | grep openssl

Finally, recently a lot of small partners come to me for helpLinux learning RoadmapAccording to my own experience, I stayed up late for a month in my spare time and organized an e-book. Whether you are interviewing or self-improvement, I believe it will help you!

Free to you, just ask you to give me a praise!

E-book | Linux development and learning Roadmap

Also hope that a small partner can join me to make this e-book more perfect!

What’s the gain? I hope the old fellow will take three strikes to show this article to more people.

Recommended reading: