Install Python 3.6 on Linux and avoid pitfalls

Install Python 3.6 on Linux and avoid pitfalls

Installation of Python 3

1. Install dependent environment

Python3 may use various dependent libraries during the installation process, so before officially installing Python3, you need to install these dependent libraries first.

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 Python 3 source code

There are two ways to download Python3 source code. One is to download it from its official website. The URL is as follows:

https://www.python.org/downloads/source/

[picture]

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

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

3. Create an installation directory

The installation directory can be created according to personal preferences, for example, here it is created in /usr/local/python3:

mkdir -p /usr/local/python3

4. Unzip the source package

Decompress 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 unzipped source package, and then configure it:

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

Then compile and install:

make
make install

6. Create a soft link for Python3

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 Python3 startup directory to 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

After the changes are complete, press Esc and enter :wq to save and exit.

8. Check whether Python3 and Pip3 are available

Execute the following command (note: V is capitalized). If the results are consistent, Python 3 has been successfully installed.

[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)

Pitfalls

In fact, there are too many posts on the Internet about the installation of Python 3, and the steps are actually similar. However, after actually installing it, you will encounter some troubles to a greater or lesser extent, especially for novices. Here are some common pitfalls:

Pitfall 1: configure: 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 to this, you can also use the source code installation method.

Pitfall 2: zipimport.ZipImportError: can't decompress data

This problem is caused by the lack of zlib related toolkits. Just package the related dependencies:

yum -y install zlib*

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

Pitfall 3: pip3: Can't connect to HTTPS URL because the SSL module is not available

This problem is that if the –with-ssl parameter is not added during the ./configure process, the SSL functions of the default installed software are not available. It just so happens that the pip3 process requires the SSL module, but since it is not specified, the function is not available. The solution is as follows:

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

Pitfall 4: Multilib version problems

This is obvious, there are multiple versions of the same library. Just delete the extra versions.

First query the existing version (take openssl as an example, check the one that 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.i686

You can see that two versions of openssl, openssl-1.0.0-27.el6_4.2.x86_64 and openssl-1.0.0-27.el6_4.2.i686, are installed in the system. We only need to keep the x86 version:

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

Update openssl again:

# yum update "openssl*"

Check openssl again and the problem is solved!

# rpm -qa | grep openssl
openssl-devel-1.0.1e-16.el6_5.7.x86_64
openssl-1.0.1e-16.el6_5.7.x86_64

Summarize

The above is the guide for installing Python 3.6 under Linux and avoiding pitfalls introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed tutorial on installing Python 3.8.1 on Linux
  • Tutorial on upgrading and installing python 3.8 and configuring pip and yum under Linux
  • Two ways to install Python3 on Linux servers
  • Detailed tutorial on installing python3 and corresponding pip environment under linux
  • How to modify the default Python version when installing Python on Linux
  • Detailed explanation of upgrading Python and installing pip under Linux
  • Python 3.7.0 installation tutorial under Linux
  • How to install Python3 on Linux and coexist with the system's own Python2

<<:  Detailed explanation of Mysql communication protocol

>>:  How to simulate enumeration with JS

Recommend

Detailed explanation of the principles and usage of MySQL stored procedures

This article uses examples to explain the princip...

Introduction to keyword design methods in web design

Many times, we ignore the setting of the web page ...

Network configuration of Host Only+NAT mode under VirtualBox

The network configuration of Host Only+NAT mode u...

Problems and solutions of using TweenMax animation library in angular

I have nothing to do recently, so I tinker with C...

How to set list style attributes in CSS (just read this article)

List style properties There are 2 types of lists ...

Tutorial on building svn server with docker

SVN is the abbreviation of subversion, an open so...

Summary of commonly used tags in HTML (must read)

Content Detail Tags: <h1>~<h6>Title T...

Detailed explanation of reduce fold unfold usage in JS

Table of contents fold (reduce) Using for...of Us...

How to deploy kafka in docker

Table of contents 1. Build Docker 2. Enter the co...

Detailed explanation of Nginx static file service configuration and optimization

Root directory and index file The root directive ...

Detailed tutorial for installing influxdb in docker (performance test)

1. Prerequisites 1. The project has been deployed...

Mysql error: Too many connections solution

MySQL database too many connections This error ob...

Vue implements start time and end time range query

This article shares with you how to query the sta...