How to upgrade all Python libraries in Ubuntu 18.04 at once

How to upgrade all Python libraries in Ubuntu 18.04 at once

What is pip

pip is a Python package management tool that provides the functions of searching, downloading, installing, and uninstalling Python packages.

Upgrade pip version

By default, the pip that comes with Ubuntu (pip 9.0.1) is based on Python 2.7. We need to reinstall pip based on Python 3:

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 modification:

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 fix has taken effect successfully: pip3 -V

The terminal prints:

pip 19.3.1 from /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 it. Here 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 the script call("pip3 install --upgrade " + ''.join(packages) + ' --user', shell=True) should be written as pip3

Next, let's check what other packages there are in the historical versions of Python:

pip3 list --outdated

The terminal prints:

Package Version Latest Type
----------- ------- ------ -----
distro-info 0.0.0 0.10 sdist
pycairo 1.16.2 1.18.1 sdist
pycups 1.9.73 1.9.74 sdist
pygobject 3.26.1 3.34.0 sdist

Then use these non-upgraded packages

pip3 install --upgrade package name to be upgraded

Commands can be upgraded one by one

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of dynamic link library calling C/C++ method in Python in Ubuntu
  • How to connect Python to MySQL database under Ubuntu system

<<:  A brief talk about MySQL pivot tables

>>:  WeChat applet realizes the nine-square grid effect

Recommend

Example code for implementing page floating box based on JS

When the scroll bar is pulled down, the floating ...

More popular and creative dark background web design examples

Dark background style page design is very popular...

A detailed introduction to the netstat command in Linux

Table of contents 1. Introduction 2. Output Infor...

Implementation process of row_number in MySQL

1. Background Generally, in a data warehouse envi...

MySQL Series 8 MySQL Server Variables

Tutorial Series MySQL series: Basic concepts of M...

How to make JavaScript sleep or wait

Table of contents Overview Checking setTimeout() ...

CSS to achieve the image hovering mouse folding effect

CSS to achieve the image hovering mouse folding e...

Install tomcat and deploy the website under Linux (recommended)

Install jdk: Oracle official download https://www...

Solve the group by query problem after upgrading Mysql to 5.7

Find the problem After upgrading MySQL to MySQL 5...

MySQL Order By Multi-Field Sorting Rules Code Example

Say it in advance On a whim, I want to know what ...

Perfect solution for vertical centering of form elements

Copy code The code is as follows: <!DOCTYPE ht...

Centos7 installation of Nginx integrated Lua sample code

Preface The computer I use is a Mac, and the oper...

Implementation of Grid common layout

No gaps on both sides, gaps between each column w...

Analysis of MySQL duplicate index and redundant index examples

This article uses examples to describe MySQL dupl...