If python2 is installed on the machine, try to ignore him and run the python script with python3, because there may be programs that depend on the current python2 environment.
Such as yum! ! ! ! !
Do not touch the existing python2 environment!
1. Install python3.6
1. Install dependencies
# 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 Python3
https://www.python.org/downloads/
1
|
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
|
3. Install python3
I personally used to install in /usr/local/python3 (the specific installation location depends on personal preference)
to create a directory:
1
|
# mkdir -p /usr/local/python3
|
Unzip the downloaded Python-3.xxtgz package (the specific package name varies depending on the specific version of Python you downloaded, for example: I downloaded Python3.6.1. Then I am here Python-3.6.1.tgz)
1
|
# tar -zxvf Python-3.6.1.tgz
|
4. Enter the decompressed directory, compile and install.
1
2
|
# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3
|
make
1
|
# make
|
make install
1
|
make install 或者 make && make install
|
5. Establish a soft chain of python3
1
|
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
|
6. Add /usr/local/python3/bin to PATH
1
2
3
4
5
6
7
8
9
|
# vim ~/.bash_profile
# .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
|
Press ESC, enter :wq and press Enter to exit.
After the modification, remember to execute the following command to make the modification in the previous step take effect:
1
|
# source ~/.bash_profile
|
Check whether Python3 and pip3 are available normally:
1
2
3
4
|
# python3 -V
Python
3.6
.
1
# pip3 -V
pip
9.0
.
1
from
/
usr
/
local
/
python3
/
lib
/
python3.
6
/
site
-
packages (python
3.6
)
|
7. If not, create a soft link of pip3 (I don't know what is the use of this step)
1
|
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
|
2. Install pip and setuptools
After all, rich third-party libraries are the advantage of python. In order to install third-party libraries more conveniently, we need to install them using the pip command.
1. Before installing pip, you need to pre-install setuptools
The command is as follows:
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python3 setup.py build
python3 setup.py install
If the environment is not set up in front, it will be hard to force it:
报错: RuntimeError: Compression requires the (missing) zlib module
We need to install the zlib-devel package in linux for support.
yum install zlib-devel
Need to recompile and install python3.5.
cd python3.6.1
make && make install
Another long compilation and installation process.
reinstall setuptools
python3 setup.py build
python3 setup.py install
2. Install pip
The command is as follows:
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz
cd pip-8.0.2
python3 setup.py build
python3 setup.py install
If there are no surprises, the pip installation is complete.
If you do not do a good job in the environment, you will encounter a kind error:
pip3 install paramiko
report this error
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Then start doing the following
yum install openssl
yum install openssl-devel
cd python3.6.1
make && make install