Search code examples
python-3.xsubprocessversion

How to install a specific version of module/library in python using a script


I have written a script that installs the required modules using the subprocess module of Python.

For instance, if I want to install altgraphs, I will write the following code:

subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'altgraph'])

but this will install the latest version of "altgraph" module. However I wish to install only a specific version of the module. Let's say I want to install the version 0.17.1, then what should be the code?


Solution

  • Specify the package version like this:

    subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'altgraph==0.17.1'])