python in ubuntu several installation methods of Summary

  • 2020-06-15 09:25:34
  • OfStack

python There are several ways to install ubuntu:

Install via the ubuntu official apt kit Install via the apt toolkit for PPA(Personal Package Archive) Install by compiling the python source code

Install via the ubuntu official apt kit


sudo apt-get install python2.7 
sudo apt-get install python3.4 

Once the installation is complete, you can confirm it with the following command


xx@ada:~$ python2.7 --version 
Python 2.7.8 
xx@ada:~$ python3.4 --version 
Python 3.4.2 
xx@ada:~$  

Install apt kit from PPA(Personal Package Archives)


$ sudo apt-get install python-software-properties 
$ sudo add-apt-repository ppa:fkrull/deadsnakes 
$ sudo apt-get update 
$ sudo apt-get install python2.7 

Tools such as the apt toolkit to install python are simple, but sometimes do not always work with the latest version. Therefore, when there is a major update to python, it is best to learn to install python2.7 by compiling directly from source code.

Install python from source compilation


$ wget -c https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz 
$ tar -xzvf Python-2.7.9.tgz 
$ cd Python-2.7.9/ 
$ LDFLAGS="-L/usr/lib/x86_64-linux-gnu" ./configure 
$ make 
$ sudo make install  

Among them, the above wget - c (url) is to download commands, parameters - c support breakpoint downloading, url is the absolute path to the target file download "- L/usr/lib/x86_64 - linux - gnu" the x86_64 linux - gnu can be found under/usr/lib /, This is x86_64 and you can see that my system is 64, so I'm going to type based on my system.

Ok, after installation, let's check, the terminal type python --version, enter, and then type which python


xx@ada:~$ python --version 
Python 2.7.9 
xx@ada:~$ which python 
/usr/local/bin/python 
xx@ada:~$  

As you can see, the installation of python2.7.9 was successful, and we found that our default version of python was es70EN2.7.9. This is because the operating system searches for commands according to the order of PATH environment variables. python under /usr/local/bin/ will be searched first than python under /usr/bin/, and will be the default VERSION of python.

There are three versions of python under ubuntu14.10, namely python2.7.8, python2.7.9 and python3.4.2, as follows:


xx@ada:~$ python --version 
Python 2.7.9 
xx@ada:~$ python2.7 --version 
Python 2.7.9 
xx@ada:~$ python3.4 --version 
Python 3.4.2 
xx@ada:~$ python2.7 
Python 2.7.9 (default, Jan 3 2015, 03:27:08)  
[GCC 4.9.1] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> exit() 
xx@ada:~$  

Of course, we can also specify the path of python to view the version of python as follows:


xx@ada:~$ /usr/bin/python --version 
Python 2.7.8 
xx@ada:~$ /usr/bin/python2.7 --version 
Python 2.7.8 
xx@ada:~$ /usr/bin/python3.4 --version 
Python 3.4.2 
xx@ada:~$ /usr/local/bin/python --version 
Python 2.7.9 
xx@ada:~$ /usr/local/bin/python2.7 --version 
Python 2.7.9 
xx@ada:~$ 

At this point, we have covered the three installation methods of python under ubuntu.

OK, Enjoy it!!!


Related articles: