How to install python3.6.5 correctly on ubuntu 16.04

1. Download python3.6.5 source code

Method 1:
 
Enter the ubuntu16.04 /usr/local folder from the terminal

$ cd /usr/local/python3

Then download the python3.6.5 source code, unzip it, and enter the python3.6.5 folder

$ wget --no-check-certificate https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
$ tar -xzvf Python-3.6.5.tgz
$ cd Python-3.6.5

If there is a problem with method 1, you can choose to download the python3.6.5 source code directly from the official website, refer to method 2.
 
Method 2:
 
Go to the official website and download the python3.6.5 source code. If you need other versions of python, you can replace python-365 with python-xxx
https://www.python.org/downloads/release/python-365/
Insert picture description here
open Python-3.6.5 The folder where .tgz is located, then right-click on the blank space and choose to open it in the terminal . Move the Python-3.6.5.tgz file to /usr/local/python3, and then enter /usr/local/python3 to decompress the python3.6.5 source code.

$ sudo mv Python-3.6.5.tgz /usr/local/python3
$ cd /usr/local/python3
$ tar -xzvf Python-3.6.5.tgz
$ cd Python-3.6.5

 

2. Compile python3.6.5 source code

$ sudo ./configure --prefix=/usr/local/python3.6.5
$ sudo make
$ sudo make install

If there is an error when compiling the first step, the solution

$ sudo apt-get install build-essential

 

3. Create a newly installed python3 link

ubuntu16.04 specifies that the python2.7 version is opened by default, so we need to revise the link.
Step 1: Back up the original link first (it is a good habit to backup before deleting the system)

$ sudo cp /usr/bin/python /usr/bin/python_bak

Step 2: Delete the original link to the python2.7 version by default

$ sudo rm /usr/bin/python 

Step 3: Re-assign the new link to python3.5 version

$ sudo ln -s /usr/local/python3/Python-3.6.5/python /usr/bin/python

 

4. Check the current python version

$ python -v

If Python 3.6.5 is displayed , the download is successful

 
 

Reference:
https://zhuanlan.zhihu.com/p/101703266

Guess you like

Origin blog.csdn.net/weixin_43901865/article/details/112576533