pyenv-virtualenv icon indicating copy to clipboard operation
pyenv-virtualenv copied to clipboard

cannot change environment in subprocess

Open mbway opened this issue 4 years ago • 0 comments

Activating a virtual environment from inside a python script running in another virtual environment fails. For example I have a 'script runner' application which has a set of scripts and their associated environments.

Here is a minimal example of the problem:

import subprocess
subprocess.run(['bash', '-c', 'source activate myenv && python -c "import sys;print(sys.executable)"'])

output:

$ /usr/bin/python runner.py  # running using an interpreter not managed by pyenv
pyenv-virtualenv: activate myenv
/home/matthew/.pyenv/versions/myenv/bin/python

$ python runner.py  # running from a pyenv environment
/home/matthew/.pyenv/versions/3.9.9/envs/otherenv/bin/python  # environment did not switch

Details

  • Ubuntu 20.04
  • x86_64
  • pyenv --version == 2.2.2
  • pyenv virtualenv --version == pyenv-virtualenv 1.1.5 (python -m venv)
  • python --version == Python 3.9.9

mbway avatar Dec 14 '21 11:12 mbway