Python is programmed to double click the method to update all installed python modules

  • 2020-06-01 10:21:31
  • OfStack

This article demonstrates a programming method for double-clicking to update all installed python modules. I will share it with you for your reference as follows:

Let's say I'm an upgrade controller. Almost every day, I check my phone and computer to see if there is any new application that needs to be updated.

The same goes for my python module. Baidu 1, found that no one will update all the modules into a command, but found a guide, mainly two commands.

pip list --outdated
pip install -U xxxx

Of course, if you just install a few python modules, it's ok to repeat the commands a few times without getting too annoying or wasting time.

With these two commands, it's enough. So I wrote a script.

import subprocess
command = "pip list --outdated"
outdatelist = subprocess.Popen (command, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell = True).stdout.readlines()
updatelist = [x.split("(")[0] for x in outdatelist ]
if updatelist :
print u" You need to update the following modules: "
print updatelist
for x in updatelist:
tempcmd = "pip install -U " + x
print subprocess.Popen (tempcmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell = True).stdout.readlines()
print u" All modules have been updated!! "
else :
print u" No modules need to be updated!! "

Isn't that easy?

More about Python related topics: interested readers to view this site "Python coding skills summary", "Python data structure and algorithm tutorial", "Python Socket programming skills summary", "Python function using techniques", "Python string skills summary", "Python introduction and advanced tutorial" and "Python file and directory skills summary"

I hope this article is helpful to you Python programming.

Related articles: