Linux Install Python3.6 and Guide to Pit Avoidance
- 2021-01-22 08:24:35
The installation of Python3
1. Install the dependency environment
Python3 may use various libraries during the installation process, so you need to install these libraries before you can officially install 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
2. Download the ES11en3 source code
There are two ways to download the source code of Python3. The first way is to download the source code from its official website, which is as follows:
The other way is through wget directly download, such as the following command:
3. Create the installation directory
mkdir -p /usr/local/python3
4. Unzip the source package
Unzip the source code package downloaded in Step 2. The command is:
tar -zxvf Python-3.6.1.tgz
5. Compile source code
First enter the unzip source code package directory, and then configure:
cd Python-3.6.1 ./configure --prefix=/usr/local/python3
Then compile and install:
make make install
6. Establish a soft link for Python3
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
7. To add/usr local/python3 / bin PATH
Edit bash_profile to modify the environment variable:
Add the startup directory for Python3 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
After finishing the changes, press ES76en, and then enter: ES77en to save and exit.
8. Check whether Python3 and Pip3 are normally available
Execute the following command (note: V is uppercase V), and if you see a result of 1, it means that Python3 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)
Avoid pit guide
In fact, for the installation of Python3, there are too many posts on the network, the steps are actually much the same. However, after the actual start to install, more or less will encounter some trouble, especially for the novice. Here are some common pits:
Pit 1: configure: error: no acceptable C compiler found in $PATH
The problem is relatively simple, is the lack of ES106en compilation environment. To install gcc:
yum install -y gcc
In addition, of course, the use of source code installation can also be.
Pit 2: zipimport.ZipImportError: can't decompress data
This problem is caused by the lack of zlib related toolkit, the relevant dependencies can be packaged:
yum -y install zlib*
After installation and then recompile the source code, you can solve.
Pit 3: pip3: Can't connect HTTPS URL because the SSL module is not available
Because in this issue. / configure process, if did not add � with ssl parameter, the default installation of the software involves ssl function is not available, just need ssl pip3 process module, and because there is no specified, so this feature is not available. The solution is as follows:
cd Python-3.6.2 ./configure --with-ssl make sudo make install
Pit 4: Multilib version problems
This is obvious: multiple versions of the same library. Just delete the extra version.
First query the existing version (in the case of openssl, check which one 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
openssl-1.0.0-27.el6_4.2.x86_64 and openssl-1.0.0-27.el6_4.2.i686:
rpm --erase --nodeps openssl-1.0.0-27.el6_4.2.i686
# yum update "openssl*"
Query 1 openssl, problem 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