Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upgrade all Python libraries at once by Ubuntu

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "Ubuntu how to upgrade all Python libraries at one time". Xiaobian shows you the operation process through actual cases. The operation method is simple and fast, and the practicality is strong. I hope this article "Ubuntu how to upgrade all Python libraries at one time" can help you solve the problem.

What is pip?

ip is a python package management tool, which provides the functions of finding, downloading, installing and uninstalling python packages.

Upgrade pip version

The default pip that comes with ubuntu (pip 9.0.1) is based on python 2.7.

We need to reinstall python3-based pip:

sudo apt-get install python3-pip

= Upgrade pip3 version:

python3 -m pip install --upgrade pip

Check the pip version of python3 and see if the following error is reported:

importerror: cannot import name main

Workaround: Edit the usr/bin/pip3 file

Before modification:

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

After modification:

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

Verification modification has taken effect successfully: pip3 -v

Terminal Print:

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

Write a python script to execute, here is the code:

import pkg_resourcesfrom 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 python3 is pip3, the pip in call("pip3 install --upgrade " + '.join(packages) + ' --user', shell=true) should be written as pip3

Next, check out Python's historical versions of the package and those:

pip3 list --outdated

Terminal Print:

package version latest type----------- ------- ------ -----distro-info 0.0.0 0.10 sdistpycairo 1.16.2 1.18.1 sdistpycups 1.9.73 1.9.74 sdistpygobject 3.26.1 3.34.0 sdist

And then use it on these unupgraded packages

pip3 install --upgrade Name of package to upgrade

Command to upgrade one by one

About "Ubuntu how to upgrade all Python libraries at once" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report