Python is usually installed in/usr/local/python3 (a specific installation location to see a person's preference, but to remember the location of the installation), because the/usr/local directory does not exist in the directory Python3, so first create a new directory:
mkdir /usr/local/python3
1. Download Python3 from official website
https://www.python.org/downloads/
2. Install dependent environment
The installation of Python3 requires these four dependencies: gcc, zlib, Zlib-devel, Openssl-devel
Then install each of the four software separately:
yum install gcc -yyum install zlib -yyum install zlib-devel -yyum install openssl-devel -y
3. Unzip the downloaded Python3 installation package
(1) because the/OPT directory is the third-party software storage directory, so we move the downloaded installation package to the/OPT directory, and then execute the decompression command in the directory:
tar -zvxf Python-3.6.4.tgz ##我的安装包是3.6.4的。
4. Compiling the installation
Enter the extracted directory and compile it within the directory. (Be sure to compile in the extracted directory, otherwise it will not compile)
cd Python-3.6.4./configure --prefix=/usr/local/python3 ##注意有位小数点符号。--prefix是指定安装目录,这里指定安装目录是/usr/local/python3make && make install
5. Configure Environment variables
echo export PATH="/usr/local/python3/bin:$PATH" >> ~/.bashrcsource ~/.bashrc
6. Check if the installation is successful
Re-open a shell, enter the command Python3 can enter into the Python interactive environment is installed successfully.
Python Learning-linux installation of Python3