I'm trying to launch a command in different Python virtualenvs using subprocess.check_call().
To activate the virtualenv (in a Python 2/3 agnostic manner), I simply append the path to my virtualenv bin (or Scripts under Windows) to the PATH and then call subprocess.check_call() with this modified environment. Like so:
environment = os.environ.copy()
environment['PATH'] = os.pathsep.join([bin_path, environment['PATH']])
subprocess.check_call("pip install -r dev_requirements.txt", env=environment)
However, what I notice is that pip installs everything in the system Python site-packages. If I change the check_call() for:
subprocess.check_call("pip install -r dev_requirements.txt", env=environment, shell=True)
Then suddenly pip operates in the virtualenv as expected.
What bothers me is that in both cases running where pip gives me the path to the virtualenv's pip first.
What could explain this odd behavior ?
 
     
     
    