What is the pip
pip is a Python package management tool that provides a Python package to find, download, install, uninstall function.
Upgrade version pip
The default Ubuntu comes pip (pip 9.0.1) is based on the version of Python2.7
We need to re-install based pip Python3 of:
sudo apt-get install python3-pip
Pip3 upgrade version:
python3 -m pip install --upgrade pip
View Python3 version of pip, if reported the following error:
ImportError: cannot import name main
Workaround: Edit usr / bin / pip3 file
- before fixing:
from pip import main
if __name__ == '__main__':
sys.exit(main())
- Modified:
from pip import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
Verify the repair has been successfully entered into force: pip3 -V
Terminal printing:
pip 19.3.1 from /home/work/.local/lib/python3.6/site-packages/pip (python 3.6)
Next, a key upgrade all Python packages
Write a Python script that can be executed, 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 my Python3 corresponding pip
Shi pip3
, so the script here call("pip3 install --upgrade " + ''.join(packages) + ' --user', shell=True)
is pip
to be writtenpip3
Then in view the history of Python version of the package as well as those who:
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
Then use those who can not upgrade packages
pip3 install --upgrade 要升级的包名
Commands one by one to upgrade