Detailed steps to install python3.6.5 on Ubuntu16.04

Environment description: Ubuntu linux 64-bit operating system

[email protected]:~$

Linux ubuntu 4.4.0-31-generic #50-Ubuntu SMPWed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[email protected]:~$ lsb_release -a

No LSB modules are available.

Distributor ID: Ubuntu

Description:    Ubuntu 16.04.1 LTS

Release:        16.04

Codename: xenial

       Unfortunately, at the time of writing this article, Ubuntu is not connected to the Internet, and it can only do the corresponding operations after downloading the installation package and uploading it. If it can be connected to the Internet, directly apt-get install python3.6.

       The default system under Ubuntu 16.04 comes with python2 and Python3.5 versions. This version is depended on by many programs in the system, so it is not recommended to delete it. If the latest Python3.6 is used, then we know that there is a difference between the compiled and installed source package and the system default package. has no effect.

       First go to the python official website to download the source package of python3, URL: https://www.python.org/downloads/release/python-365/

       After entering, click Downloads in the navigation bar, or you can place the mouse on Downloads and select Source code from the pop-up menu, which means the source code package. Here, select the latest version 3.6.5. Of course, there are many other historical versions below. After clicking in, you can see it at the bottom of the page. to download link 

       Select Download Gzipped source tarball, after downloading it is Python-3.6.5.tgz

 

1.    Upload the installation package. Open the terminal and use the command cd to enter the folder where the file is located

[email protected]:~/workspace$pwd

/home/python/workspace

2.    Unzip the file 

tar xfzPython-3.6.5.tgz 

Note: The xfz command is used here , and the -xvzf command is not recommended , because the released folder needs root privileges to be changed or deleted.

[email protected]:~/workspace$tar xfz Python-3.6.5.tgz

[email protected]:~/workspace$ll

Total usage 22472

drwxrwxr-x  4 python python 4096 5  12 19:06 ./

drwxr-xr-x 30python python     4096 1226 22:56 ../

drwxrwxr-x  2 python python 4096 1226 22: 56python /

drwxr-xr-x 16python python     4096 3  28 18:24Python-3.6.5/

-rwxrw-rw-  1 python python 22994617 5  12 18: 40Python-3.6.5.tgz *

[email protected]:~/workspace$

3.    Enter the unzipped folder and add the configuration 

cd Python-3.6.5 /

./configure "--prefix=/usr/bin/python3.6"

4.    To configure is the folder required to install Python . After the configuration is complete, the terminal will display the following paragraph, you can choose to ignore it without affecting subsequent operations. 

If you want arelease build with all optimizations active (LTO, PGO, etc), 

please run./configure –enable-optimizations

5.    Compile the source code 

sudo make

The compilation process takes a few minutes, and an error may be reported, depending on the version of gcc you have installed .

6.    Execute the installation 

sudo makeinstall 

The installation process lasts for a few minutes. After the installation is successful, the installed Python is in the /usr/bin/python3.6 folder of the computer .

python @ ubuntu: / usr / bin $ cd python3.6 /

[email protected]:/usr/bin/python3.6$ls

bin  include lib  share

[email protected]:/usr/bin/python3.6$pwd

/usr/bin/python3.6

7.    Modify the default Python version 

Ubuntu16.04 version integrates Python 2.7 and 3.5 versions. The original python in the system is in /usr/bin/python . You can see through ls -l that python is a soft link that links to python2.7 in this directory.

We need to delete this default link first, and then create a new soft link for python3.6 . . First, make sure that the pointer of the terminal has returned to the root directory, and then perform the following operations.

8. You    need to delete the original Python link file : rm /usr/bin/python

Note that if the terminal prompts: rm: cannot delete '/usr/bin/python': insufficient permissions, then you need to use sudo or open root permissions to delete the link.

9.    Create a link to Python 3.6 . If the permission is not enough, use root or sudo plus the command:

 ln -s /usr/bin/python3.6/bin/python3.6/usr/bin/python

  1. Query Python version 
    [email protected]:~$ python -V

Python 3.6.5 

If the display is python3.6.5 , the installation is successful!

 

 

Tags: Detailed steps to install python3.6.5 on Ubuntu16.04

python

Related: Detailed steps to install python3.6.5 on Ubuntu16.04