Python module update in code

My question relates to this question: Installing the python module inside the code , but includes updating the module.

I tried

packages=['apscheduler','beautifulsoup4','gdata']

def upgrade(packages):
    for package in packages:
        pip.main(['install --upgrade', package])

and

def upgrade(packages):
    for package in packages:
        pip.main(['install', package + ' --upgrade'])
+4
source share
3 answers

Give it a try pip.main(['install', '--upgrade', package]).

"- upgrade" is a separate command line argument, so you need to pass it separately to main.

+10
source

BrenBarn's answer matches the OP code style, but Richard Wheatley's answer is closer to my code.

There are several issues in Richard’s answer that I would like to fix, and I didn’t want to edit it, because the differences were quite significant.

from subprocess import call

my_packages = ['apscheduler', 'beautifulsoup4', 'gdata']

def upgrade(package_list):
    call(['pip', 'install', '--upgrade'] + package_list)

Notes:

  • pip (subprocess pip, )
  • shell=True call() ( subprocess), . ( , .)
  • pip install , --upgrade .
  • Python, .
+1

, , , , . .

import pip
from subprocess import call

packages=['apscheduler','beautifulsoup4','gdata']

def upgrade(packages):
    for package in packages:
        call("pip install --upgrade " + package, shell=True)

"shell = True" , shell = True , , .    import pip , pip.main, .

, :   

packages=['apscheduler','beautifulsoup4','gdata']

def upgrade(packages):
    for package in packages:
        call("pip install --upgrade " + package)

, . .

0

All Articles