[Python] Automatically upgrade all packages installed by pip

#-*- coding:utf-8 -*-

import os

import re

def update():

    pipList = os.popen('pip3 list').readlines() #This is equivalent to entering pip3 list in cmd to show all packages installed by pip3

    #print(pipList)

    p = re.compile(r'\(.*?\)')#Because the data stored in pipList is like pefile (2017.11.5), but we only need pefile and don’t need the contents in (), so we need to use regular expressions to remove () and the contents inside.

    try:

        for i in pipList:

            content = p.sub('',i) #Use regular expressions to remove useless information

            print(content)

            os.system('pip3 install --upgrade' + ' '+content) #Start updating content

    except:

        pass






if __name__=='__main__':

    update()

At this time, we need to go to the directory where the file is located, and then enter python update.py on the command line. At this time, we will start to automatically upgrade all packages as shown below

If there is no error, the script will continue to execute until all packages have been updated. Of course, the update process will be interrupted due to network speed. Then run the program again when the internet speed is good, remember to be in the console!

Intelligent Recommendation

pip update all installed packages

1. pip does not have a method to update all packages. 2. The command for pip to update a single package is as follows: 3. Use another plugin to update all packages, plugin name: pip-review, plugin nee...

[Environment] the latest in a python method to upgrade all packages installed

Reproduced in: https: //my.oschina.net/u/3579120/blog/1533304...

Quickly upgrade all pip expired packages

Create a new file, such as upgrade_all.py Run upgrade_all.py If using python2, remove 3 Note that windows goes down sudo...

pip change source, upgrade all packages

In the windows file manager, enter%APPDATA%,Enter Then it will locate a new directory, create a pip folder in this directory, and then create a pip.ini file in the pip folder Finally, enter the conten...

With pip install the upgrade installed packages of additional packages to tabulate bag, for example

Pip install additional packages with upgrades installed to tabulate bag, for example Pypi official website to view the presentation tabulate the package and found tabulate 0.7.6 supports the beautific...

More Recommendation

Python PIP Delete All Packages

1) Export all packages 2) Delete all packs or...

Quickly upgrade all python packages

Run the following code block to upgrade all packages with Tsinghua source...

Python upgrade pip and install opencv, moviepy packages

Create a new python directory path in environment variables python -m pip install --upgrade pip upgrade pip, pip install opencv-python install opencv package pip install moviepy installs moviepy packa...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top