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