I am writing a program that should install dependencies using pip. What is the right way to do this and why?
Ideally, this should be agnostic for the platform, but the program will run on a Linux machine.
Method 1: pip.main()
import pip
args = ['param1', 'param2']
version = 0.1
package = ['some_package=={}'.format(version)]
pip.main(['install'] + args + package)
Method 2: subprocess.call()
import subprocess
import sys
version = 0.1
package = 'some_package'
subprocess.call([sys.executable, '-m', 'pip', 'install', '{}=={}'.format(package, version)])
Petar source
share