How to install python on ubuntu

藏色散人
Release: 2019-10-02 17:30:19
Original
5818 people have browsed it

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) apt Toolkit installation

● Installation by compiling python source code

Installation through ubuntu official apt toolkit

sudo apt-get install python2.7  
sudo apt-get install python3.4
Copy after login

After the installation is completed, you can use the following Confirm with the command

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

Install the apt tool package 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
Copy after login

It is similar to using the apt tool package to install python tools. Although it is simple, it sometimes does not work. You must 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

$ 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
Copy after login

where , the above wget -c (url) is the download command, the parameter -c indicates support for breakpoint download, and url is the absolute path of the target file download "-L/usr/lib/x86_64-linux-gnu" in x86_64-linux- 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:~$
Copy after login

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/ and will be used 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:

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:~$
Copy after login

Of course, we can also specify python The path, in order to check the python version, is 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:~$
Copy after login

So far, we have introduced the three installation methods of python under ubuntu.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template