Python 3.x complete installation and configuration (Linux version)
At present, most Linux systems from version 2.x python belt is, in order to meet the higher level of demand, we need to replace the system comes with the original version of python into a newer version.
Here to CentOS 7 system, for example, replace python3.6 version
spare time finishing notes, any inadequacies in the wrong place, we sincerely welcome you pointed out.
A, Python3.6 installation package
Use wget command in the Linux terminal, downloaded from the official website www.python.org tgz installation packages
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
Second, extract the installation package
tar -xvf Python-3.6.0.tgz
Third, the configuration-dependent environment
Before the formal configuration python environment, we need to first download a good dependencies: gcc and zlib
yum install gcc
yum install -y zlib zlib-devel
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel
After a successful silent installation, we switch to the Modules directory of good Python-3.6.0-extracting files, configuration files
vi Setup.dist
The content of this modified form (# in front of the contents of the file can be deleted before the original):
Next we need to configure the installation location of python3
here installed by default to / usr / local / python3 folder, users can also according to arrange their own needs in a different directory
enter the command:
./configure --prefix=/usr/local/python3
After completing see the following prompt the configuration was successful
this sentence means "if you want to publish all optimized version (LTO, PGO etc.) release, run ./configure --enable-optimizations"
We do not care for it
make && make install
See the following prompt the installation is successful:
Fourth, replace the old version
Compared to replace the old version, more here we suggest that you keep the old version and then add a connection to the new version
because of the environment I used some components depend python2, while python2 relationship and there is a big difference between syntax 3, if the direct would later use to replace it cause some trouble, so I chose here to create a new command python3
ln -n /usr/local/python3/bin/python3 /usr/bin/python3
If you choose to replace the old version, see the following sections this
first point we need to get rid of old versions of the soft connection
mv /usr/bin/python /usr/bin/python_bak
Create a soft link
ln -s /usr/local/python3/bin/python3 /usr/bin/python
Check the
connection is completed, we have to execute: python -V
displays the version number, indicating that the replacement has been successful
but we now enter the pip in the terminal, you will find show "bash: pip: not found" prompt
because this time although we have installed and configured the python, but not because of the pip configure, and therefore can not be used directly pip command
Five, pip configuration
Add to pip soft connection
ln -n /usr/local/python3/bin/pip3 /usr/bin/pip
Until then enter the command: pip -V
can be found pip command has been able to normal use, but this time we will find python3.6 default comes pip is just 9.0 version, is relatively low, we need it to do an upgrade, in before upgrading, we first pip mirrored switch to domestic sources.
Note: If you are using a built python3 command, use the "python3 -m pip install" in the next, then use pip install package format
Six, pip replace domestic sources
1. Change the home directory (the root directory) under
2. Create a folder .pip
mkdir .pip
Note: pip foregoing points can not be omitted, the file name generally indicates little hidden folder
3. .pip switch to the next folder, and create a new file pip.conf
vi pip.conf
Enter the following in the file, will replace watercress pip Source:
[global]
timeout=6000
index-url=http://pypi.douban.com/simple
trusted-host=pypi.douban.com
After completing the save and exit can be
in addition to watercress source, there is also recommend to you a few common source of domestic station:
https://pypi.tuna.tsinghua.edu.cn/simple/ # Tsinghua University
https://mirrors.aliyun.com/pypi/simple/ # aliyun
https://pypi.douban.com/simple/ # watercress
https://pypi.mirrors.ustc.edu.cn/simple/ # University of Science and technology of China
https://pypi.hustunique.com/ # Huazhong University of Science and technology
This time to enter to upgrade pip:
python -m pip install --upgrade pip
There are suggested
so far have all been successfully configured python Well!
7, on the yum
Another point, some users choose to replace the old version before using python command yum command error occurs
because yum uses a syntax python2, and there is a large python subversion of between 2 and 3 versions, so python3 no longer supported python2 syntax format
where we need to be slightly adjusted yum file
vi /usr/bin/yum
Find this sentence at the beginning of the file
#!/usr/bin/python
The back of the python to point to your python2.x version of bin command, this would resolve the