Home >Backend Development >Python Tutorial >How to install python on ubuntu
How to install python on ubuntu?
There are several installation methods for python under ubuntu:
● Install through ubuntu’s official apt tool package
● Through PPA ( Personal Package Archive)'s apt toolkit installation
● Installation by compiling python source code
● Installation through ubuntu official apt toolkit
[html] view plain copy sudo apt-get install python2.7 sudo apt-get install python3.4 安装完成后, 可以用下面的命令进行确认 [plain] view plain copy xx@ada:~$ python2.7 --version Python 2.7.8 xx@ada:~$ python3.4 --version Python 3.4.2 xx@ada:~$ 从PPA(Personal Package Archives) 安装apt工具包 [plain] view plain copy $ sudo apt-get install python-software-properties $ sudo add-apt-repository ppa:fkrull/deadsnakes $ sudo apt-get update $ sudo apt-get install python2.7
Similar to installation using apt toolkit Although python tools are simple, sometimes they may not be able to install the latest version. Therefore, when there is an important update to python, we'd better learn to compile and install python2.7 directly from the source code.
Compile and install python from the source code
[plain] view plain copy $ 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 the download command, the parameter -c indicates support for breakpoint download, url is the absolute path of the target file download
x86_64-linux- in "-L/usr/lib/x86_64-linux-gnu" gnu can be found under /usr/lib/. This is x86_64. You can see that my system is 64. Type it here according to your own system.
Okay, after the installation is complete, let’s check it. Type python --version in the terminal, press Enter, and then type which python
xx@ada:~$ python --version Python 2.7.9 xx@ada:~$ which python /usr/local/bin/python xx@ada:~$
It can be seen that python2.7.9 was installed successfully, and we found that our default The python version has become python2.7.9. This is because when the operating system searches for commands, it searches in the order of the PATH environment variable. python under
/usr/local/bin/ will be searched first than python under /usr/bin/ to, and serve as the default python version.
Then I have three versions of python under ubuntu14.10, namely python2.7.8, python2.7.9, python3.4.2, as follows:
[plain] view plain copy 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 python The path, to check the python version, is as follows:
[plain] view plain copy 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 introduced the three installation methods of python under ubuntu.
Related recommendations: "Python Tutorial"
The above is the detailed content of How to install python on ubuntu. For more information, please follow other related articles on the PHP Chinese website!