The installation of Python3

1. Install dependent environments

Python3 may use various dependency libraries during the installation process, so you need to install these dependencies before installing Python3.

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
Copy the code

2. Download Python3 source code

There are two ways to download the Python3 source code. One is from the Python3 website:

https://www.python.org/downloads/source/
Copy the code

[images]

Another option is to download it directly via wget, such as the following command:

Wget HTTP: / / https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgzCopy the code

3. Create an installation directory

The installation directory can be created to your liking, such as in /usr/local/python3:

mkdir -p /usr/local/python3
Copy the code

4. Decompress the source package

Decompress the source package downloaded in step 2 as follows:

The tar ZXVF Python - 3.6.1. TGZCopy the code

5. Compile source code

Enter the directory of decompressed source package first, and then configure:

CD Python - 3.6.1. / configure -- prefix = / usr/local/python3Copy the code

Then compile, then install:

make
make install
Copy the code

6. Set up the Python3 soft link

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
Copy the code

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

Edit bash_profile to modify environment variables:

vim ~/.bash_profile
Copy the code

Add the Python3 startup directory under the PATH variable:

# .bash_profile

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

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/python3/bin

export PATH
Copy the code

After the modification is complete, press Esc and enter :wq to save the configuration and exit.

8. Check whether Python3 and Pip3 are available

Execute the following command (note that V is uppercase V). If you see the same results, Python3 has been installed successfully.

[alvin@VM_0_16_centos ~]$python3 -v Python 3.6.1 [alvin@VM_0_16_centos ~]$pip3 -v PIP 9.0.1 from / usr/local/lib/python3.6 / site - packages (python 3.6)Copy the code

Avoid pit guide

In fact, there are so many posts on the Internet about Python3 installation that the steps are pretty much the same. However, after the actual hands-on installation, there is more or less a bit of trouble, especially for beginners. Here are some common ones:

Crater 1: configure: error: no acceptable C compiler found in $PATH

The problem is simply the lack of a GCC compilation environment. Install GCC:

yum install -y gcc
Copy the code

Of course, in addition to the use of source code installation can also be.

2: the pit zipimport. ZipImportError: can ‘t decompress the data

This problem is caused by the lack of zlib toolkits.

yum -y install zlib*
Copy the code

Recompile the source code after installation, can be solved.

Pit 3: PIp3: Can’t connect to HTTPS URL because the SSL Module is not available

Pip3 requires the SSL module, and this function is unavailable because it is not specified./configure does not include the — with-ssl parameter. The solutions are as follows:

CD python-3.6.2./configure --with-ssl make sudo make installCopy the code

Pit 4: Multilib version Problems

There are multiple versions of the same library. Just delete the extra version.

Query the existing version first (take OpenSSL as an example, check which version conflicts)

# RPM - qa | grep openssl openssl devel - 1.0.0-27 el6_4. 2. X86_64 openssl 1.0.0-27 el6_4. 2. X86_64 Openssl 1.0.0-27. El6_4. 2. I686Copy the code

Openssl-1.0.0-27.el6_4.2.x86_64 openSSL-1.0.0-27.el6_4.2.i686 openSSL: openSSL-1.0.0-27.el6_4.2.i686 openSSL: openSSL-1.0.0-27.el6_4.2.i686 openSSL: openSSL-1.0.0-27.el6_4.2.i686

RPM -- erase -- nodeps openssl 1.0.0-27 el6_4. 2. I686Copy the code

Update openSSL:

# yum update "openssl*"
Copy the code

Query openSSL again, problem solved!

# RPM - qa | grep openssl openssl devel - e - 16. 1.0.1 el6_5. 7. X86_64 openssl - e - 16 1.0.1. El6_5. 7. X86_64Copy the code

> < p style = “max-width: 100%; clear: both
#### read all is true love, a praise to walk again? Your “sanlian” is the biggest motivation for liang Xu’s continuous creation!
1\. Follow the ** original ** * public account “** Liangxu Linux**”, the first time to get the latest Linux dry goods!
2. Public account background reply [information] [interview] [resume] to get selected first-line big factory interview, self-improvement, resume and other information.
3\. Follow my blog: [lxlinux.net]([http://www.lxlinux.net]](http://www.lxlinux.net%29/)