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

Nodejs error handling process record

This article takes the connection error ECONNREFU...

How to use lazy loading in react to reduce the first screen loading time

Table of contents use Install How to use it in ro...

jQuery uses the canvas tag to draw the verification code

The <canvas> element is designed for client...

Vue.js application performance optimization analysis + solution

Table of contents 1. Introduction 2. Why do we ne...

Detailed steps to install VMware Tools from scratch (graphic tutorial)

VMware Tools is a tool that comes with VMware vir...

Sample code for implementing rolling updates of services using Docker Swarm

1. What is Docker Swarm? Docker Swarm is a cluste...

Implementation of CSS child element selection parent element

Usually a CSS selector selects from top to bottom...

Network management and network isolation implementation of Docker containers

1. Docker network management 1. Docker container ...

How to make your own native JavaScript router

Table of contents Preface Introduction JavaScript...

Detailed tutorial on deploying Apollo custom environment with docker-compose

Table of contents What is the Apollo Configuratio...

Summary of common Linux distribution mirror source configuration

I have been researching Linux recently and tried ...