How to upgrade all Python libraries on Ubuntu 18.04

What is pip

pip is a Python package management tool, which provides functions for searching, downloading, installing, and uninstalling Python packages.

Upgrade pip version

By default, pip (pip 9.0.1) that comes with Ubuntu is based on Python2.7
We need to reinstall pip based on Python3:

sudo apt-get install python3-pip

= Upgrade pip3 version:

python3 -m pip install --upgrade pip

Check the pip version of Python3, if the following error is reported:

ImportError: cannot import name main

Solution: Edit the usr/bin/pip3 file

before fixing:

from pip import main
if __name__ =='__main__':
 sys.exit(main())

After modification:

from pip import __main__
if __name__ =='__main__':
 sys.exit(__main__._main())

Verify that the repair has taken effect successfully: pip3 -V

Terminal print:

pip 19.3.1from/home/work/.local/lib/python3.6/site-packages/pip(python 3.6)

Next, upgrade all Python packages with one click

Just write a Python script to execute, the following is the code:

import pkg_resources
from subprocess import call
 
for packages in[dist.project_name for dist in pkg_resources.working_set]:call("pip3 install --upgrade "+''.join(packages)+' --user', shell=True)

Because the pip corresponding to my Python3 is pip3, the pip in call("pip3 install –upgrade ”+ ”.join(packages) + '-user', shell=True) in the script here should be written as pip3

Next, check the historical version of Python packages and those:

pip3 list --outdated

Terminal print:

Package   Version Latest Type
-----------------------------
distro-info 0.0.00.10  sdist
pycairo   1.16.21.18.1 sdist
pycups   1.9.731.9.74 sdist
pygobject  3.26.13.34.0 sdist

Then use these unupgraded packages

pip3 install --upgrade Package name to be upgraded

Command to upgrade one by one

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

How to upgrade all Python libraries on Ubuntu 18.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to install Python 3.8 on Ubuntu 18.04
How to upgrade to Ubuntu 20.04
How to install Python2 on Ubuntu20.04 ubuntu/focal64
How to upgrade to Ubuntu 20.04
How to play happily with Python3 on Ubuntu
[Practice] How to install python3.6 on Ubuntu system
Upgrade Ubuntu 18.04 on Azure to 18.10
How to upgrade to Ubuntu 16.04 LTS
How to install Ruby on Ubuntu 20.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 Node.js on Ubuntu 16.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 MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.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