Use python -V Command query current python Version of , Be careful V It's capital
[email protected]:~/ download $ python -V Python 2.7.12
wget http://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz tar -xzvf Python-3.6.6.tgz
First you need to compile , And then install it , Before compiling , First in /usr/local Directory create a new folder python3 As a new directory, avoid covering old ones , Be careful ： To switch to root user （ Switch users to su command ）, Otherwise, you will be prompted that you have no permission .
Switch to the directory after decompression , Then enter the following command
This process takes a little longer , After execution , Type in the command
make make install
If installed for the first time , Input... For the first time make When , Will fail , The report has the following mistakes ：
zipimport.ZipImportError: can’t decompress data
This is a problem , The main reason is the lack of zlib Related toolkits lead to , install zlib* Just go .
install zlib* The way , The most popular way to find it on the Internet is as follows
yum -y install zlib*
I try to use commands like this , But the prompt did not install yum, Use sudo apt-get install yum install yum after , Indicates that there is no available warehouse , Prompt for execution yum repolist all see , It turns out that 0.
Here's how ,ubuntu The default package management is not yum, It is dpkg, During installation , Use apt-get. Then install zlib Use the following command ：
sudo apt-get install zlib*
Installation successful ！ Then execute again make and make install, Finish compiling and installing , Let's create a soft link .
First change the old version of the link , The order is as follows
mv /usr/bin/python /usr/bin/python_old2
Now , Enter at the command line python_old2 -V, You'll see the version number of the old version .
by python3 Create a soft connection
ln -s /usr/local/python3/bin/python3 /usr/bin/python
And then execute python -V, You'll see that the version number is already 3.6.6 了 , Be accomplished ！
In this way , Multiple can be installed python edition , adopt ln -s Specify different soft links , for example ：
The following links have all of them python Version of , Can pass wget download , It can also be downloaded directly from the browser