I now this is an old thread but I have come across it many times and I think I should give another solution since I've used this one. To me this is more user-friendly.
import pip
from subprocess import call
packages=['apscheduler','beautifulsoup4','gdata']
def upgrade(packages):
for package in packages:
call("pip install --upgrade " + package, shell=True)
After reading the following Actual meaning of 'shell=True' in subprocess post, it appears that the shell=True command was not needed and is probably not the best idea.
import pip
is not needed since I do not call pip.main
as was seen in some previous answers.
So the new code could be:
from subprocess import call
packages=['apscheduler','beautifulsoup4','gdata']
def upgrade(packages):
for package in packages:
call("pip install --upgrade " + package)
As for the other answers, I prefer passing the specific string and loop.
You will not get a performance hit or gain using either method.