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 the Python Library in Ubuntu18.04

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to upgrade Python libraries in Ubuntu 18.04? I believe that many inexperienced people are helpless about this. For this reason, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Python is mainly used for: 1. Web development;2. Data science research;3. Web crawler;4. Embedded application development;5. Game development;6. Desktop application development.

Upgrade pip version

The default pip that comes with Ubuntu (pip 9.0.1) is based on Python 2.7.

We need to reinstall Python 3 based pip:

sudo apt-get install python3-pip

= Upgrade pip3 version:

python3 -m pip install --upgrade pip

Check the pip version of Python 3 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 successfully takes effect: 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 in the script

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 Package name to upgrade Having read this, do you know how to upgrade Python libraries in Ubuntu 18.04? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

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

Servers

Wechat

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

12
Report