Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.executable and sys.path are wrong when running virtualenv python in subprocess on macOS #1581

Closed
rdbisme opened this issue Feb 11, 2020 · 3 comments

Comments

@rdbisme
Copy link

rdbisme commented Feb 11, 2020

When launching the virtualenv python bynary from a subprocess from the system binary, the environment in which the subprocess call is running looks wrong: e.g. it returns the system python binary as sys.executable.
If the virtualenv is created using venv, things work as expected.

On Linux the bug is not present.

Python Details

Python 3.7.6 (default, Dec 22 2019, 01:09:06)
[Clang 11.0.0 (clang-1100.0.33.12)] on darwin

OS details

10.15.3 (but I could also reproduce on 10.14)

If I do (using the system python): python -m venv $WORKON_HOME/test-venv and then:

$> which python
/opt/local/bin/python
$>python
>>> import subprocess
>>> subprocess.check_output('/Users/rubendibattista/.envs/test-venv/bin/python -c "import sys; print(sys.executable)"', shell=True)
b'/Users/rubendibattista/.envs/test-venv/bin/python\n'

On the other hand, if I create a virtual env using virtualenv:

$> virtualenv $WORKON_HOME/test-virtualenv
Using base prefix '/opt/local/Library/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/rubendibattista/.envs/test-virtualenv/bin/python3.7
Also creating executable in /Users/rubendibattista/.envs/test-virtualenv/bin/python
Installing setuptools, pip, wheel...
done.

And then

$> $> which python
/opt/local/bin/python
$> python
>>> import subprocess
>>> subprocess.check_output('/Users/rubendibattista/.envs/test-virtualenv/bin/python -c "import sys; print(sys.executable)"', shell=True)
b'/opt/local/bin/python\n'
@rdbisme rdbisme changed the title sys.executable and sys.path is wrong when running virtualenv python in subprocess on macOS sys.executable and sys.path are wrong when running virtualenv python in subprocess on macOS Feb 11, 2020
@gaborbernat
Copy link
Contributor

gaborbernat commented Feb 11, 2020

Judging from the output of that virtualenv creation you're using the old legacy version of virtualenv (<16.7.9). That's no longer maintained. Please try the latest version 20.0.2 and report back if this is still an issue.

@asottile
Copy link
Contributor

the output is due to framework builds which are particularly fickle, you'll likely need a workaround similar to this

@rdbisme
Copy link
Author

rdbisme commented Feb 11, 2020

I was using the version provided by Macports.

Upgrading virtualenv seems to fix the bug:

$> virtualenv --version
virtualenv 20.0.2 from /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/virtualenv/__init__.py

virtualenv $WORKON_HOME/test-virtualenv
created virtual environment CPython3Posix(dest=/Users/rubendibattista/.envs/test-virtualenv, clear=False, global=False) with seeder FromAppData pip=latest setuptools=latest wheel=latest app_data_dir=/Users/rubendibattista/Library/Application Support/virtualenv/seed-v1 via=copy
$> python
>>> import subprocess
>>> subprocess.check_output('/Users/rubendibattista/.envs/test-virtualenv/bin/python -c "import sys; print(sys.executable)"', shell=True)
b'/Users/rubendibattista/.envs/test-virtualenv/bin/python\n'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants