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

MySQL Series 4 SQL Syntax

Table of contents Tutorial Series 1. Introduction...

Vue directives v-html and v-text

Table of contents 1. v-text text rendering instru...

Some small methods commonly used in html pages

Add in the <Head> tag <meta http-equiv=&q...

Detailed tutorial on building nextcloud private cloud storage network disk

Nextcloud is an open source and free private clou...

How to implement Linux automatic shutdown when the battery is low

Preface The electricity in my residence has been ...

MySQL grouping queries and aggregate functions

Overview I believe we often encounter such scenar...

How to export mysql table structure to excel

The requirements are as follows Export the table ...

How to modify the initial password of a user in mysql5.7

When users install MySQL database for the first t...

js implements clock component based on canvas

Canvas has always been an indispensable tag eleme...

Detailed explanation of basic management of KVM virtualization in CentOS7

1. Install kvm virtualization : : : : : : : : : :...

CSS: visited pseudo-class selector secret memories

Yesterday I wanted to use a:visited to change the...

Vue implements Dialog encapsulation

Table of contents Vue2 Writing Vue3 plugin versio...