How to upgrade all Python third party packages and install Python packages with one click


1、 What is PIP

Pip is a python package management tool, which provides the functions of finding, downloading, installing and unloading Python packages.

2、 Upgrade PIP version

1. The default PIP (PIP 9.0.1) of Ubuntu is based on Python 2.7

2. We need to re install PIP based on Python 3:

sudo apt-get install python3-pip

3. Upgrade PIP3 version:

python3 -m pip install --upgrade pip

4. Check the PIP version of Python 3. If you report the following error:

ImportError: cannot import name main

Solution: edit the usr / bin / PIP3 file

Before revision:

from pip import main
if __name__ == '__main__':

After modification:

from pip import __main__
if __name__ == '__main__':

Verify that the repair has come into effect successfully: PIP3 – V

Terminal printing:

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

5. Upgrade all Python packages with one click

Write a python script to execute. 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 Python 3 is PIP3, the PIP in the script call (“PIP3 install — upgrade” + “. Join (packages) + ‘– User’, shell = true) should be written as PIP3

Next, let’s look at the packages of Python’s historical version

pip3 list --outdated

Terminal printing:

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 

And then use the

PIP3 install -- upgrade package name

Order to upgrade one by one. I don’t often use those four packages. I’m too lazy to upgrade( PS: it’s inconvenient to take a screenshot of the newly installed Ubuntu 18.04

Knowledge point extension: install Python package on Ubuntu 18.04

Recently, running two models at the same time, the cloud server can’t stand it,

Set up a company’s windows host, washed into Ubuntu 18.04 for my MBP remote SSH. Cool~

1. Configure ssh server

2. Install python, etc

Unbuntu18.04 comes with Python 3.6.8

1. Install PIP3 and execute

sudo apt install python3-pipi

2. Install vim and execute

sudo apt install vim

2. Configure the image first, and then install the python packages

pip3 install some-package

Torch actually shows that it takes 20 hours to download, or use Tsinghua pypi mirror image 8~

Note that an error may be reported after upgrading pip10

Error: could not install packages due to an environment error: [errno 13] insufficient permissions: ‘/ usr / local / lib / Python 3.6 / dist packages / defusedxml-0.6.0. Dist Info’
Consider using the `–user` option or check the permissions.

Add — user after install

pip3 install -user some-package


The above is a small series to introduce you to the Ubuntu 18.04 one button upgrade Python all third-party packages and install Python package method, I hope to help you, if you have any questions, please leave me a message, small series will reply to you in a timely manner. Thank you very much for your support to developer!
If you think this article is helpful to you, please reprint, please indicate the source, thank you!