How to play happily with Python3 on Ubuntu

This should not actually be a minority article

Ubuntu is the most popular among Linux desktop distributions. Although the Linux and Windows families are not on the same scale, the community is still quite active.

There are also many people using Ubuntu desktop systems in China. Of course, most of them are used as virtual machines. Mine is Ubuntu installed on a physical machine. I want to create an all-round programming environment. In fact, I found a problem when developing the backup scanning script before. The pip3 installation library file of Python3 is not directly installed into python3.6.3. This must be very daunting. You can understand it after reading the following introduction!


Ubuntu 16.04 LTS

The long-term support version is chosen for stability. I will definitely reinstall the system when the long-term support version comes out on April 18.

16.04 The Python environment that comes with the version of Ubuntu is Python2.7+ Python 3.5.2

Many core functions in the Ubuntu system use Python a lot, so when programming, I don’t want to add various libraries to the built-in Python and use it for parsing. After all, once it crashes, the system may hang. Moreover, Python 3 is updated very quickly, and it has been released to Python 3.6.4 version. I don't want to use the old version anymore. The above thoughts made me plan to install Python 3.6.4 on the original basis.

Clarify the problem

Ideal state:

Python 2.7 + Python 3.5.2 + Python 3.6.4

python -----> Python 2.7

python2 ----> Python2.7

python3 ----> Python 3.6.3

In fact, the above is all very easy to solve, the key is pip

pip ------> python 2.7

pip3 ----> python3.6.4

python -m pip install package_name ----> python 2.7

python3 -m pip install package_name ----> python 3.6.4

My question before is that python3 corresponds to python3.6.4

But pip3 corresponds to pyhton3.5.2, which leads to a problem. There is no way to add libraries to Python3.6.4. Pyhton does not have a powerful library, and there may be nothing in itself. For example, my previous backup scanning tool called request The library, after that, it was very simple to issue the package. This problem has troubled me for more than a day, and it crashed my system yesterday.

In fact, there are a lot of this problem on the Internet. The key problem is that most of them just did the previous step, which is to install Python 3.6.x, which did not solve the pip3 problem, and then there is no more. What's more, the wrong method is still written there tirelessly. In the end, it succeeded. In the end, even I began to think whether our system was different (in fact, it may be caused by some dependency updates)


Now I will talk about how to do it. Before doing it, consider whether you really have this need.

installation steps

Update and upgrade

sudo apt-get update

sudo apt-get upgrade

Download the source package from the official website

https://www.python.org/downloads/release/python-364/

Unzip the compressed package

tar -xfz Python-3.6.4.tgz

Install dependencies

sudo apt-get install libssl-dev

sudo apt-get install zlib1g-dev

Configure source package

. /configure --with-ssl

The latter parameters are very important

Compile

make

installation

sudo -H make install

This is installed


Verification is successful

python3 -V

The above display shows that the installation is successful

pip3 -V

You can see that pip3 has successfully pointed to python3.6

PS: Explain the place marked in orange just now

If you don't use --with-ssl, everything can be installed successfully after the installation is complete, but when pip3 installs the library files, it will report an error that TLS/SSL cannot be found

Recommended Posts

How to play happily with Python3 on Ubuntu
How to install Python 3.8 on Ubuntu 18.04
How to install Python2 on Ubuntu20.04 ubuntu/focal64
How to install Prometheus with Docker on Ubuntu 14.04
How to upgrade all Python libraries on Ubuntu 18.04
How to manage Jenkins with Rancher on Ubuntu 14.04
[Practice] How to install python3.6 on Ubuntu system
How to start a blog with Hexo on Ubuntu 14.04
How to protect Apache with Let's Encrypt on Ubuntu 16.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install Go on Ubuntu 20.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on CentOS 8
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to deploy Django on Ubuntu 14.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Python on CentOS 8
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to secure Nginx on Ubuntu 14.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to uninstall software on Ubuntu
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04