Skip to content

Blacklist __PYVENV_LAUNCHER__ env var in subprocess calls #46

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

Merged
merged 1 commit into from
Feb 3, 2020

Conversation

irvinlim
Copy link
Contributor

@irvinlim irvinlim commented Feb 1, 2020

I encountered a weird bug in which the shebang in any binaries created using venv.install points to the wrong Python path, instead of the Python binary created within the virtualenv. It also seems that this bug is specific to macOS, or maybe just to Homebrew installs of Python.

If I do the following:

$ python
>>> from virtualenvapi import VirtualEnvironment
>>> env = VirtualEnvironment('.venv')
>>> env.install('yapf')
>>> ^D
$ head -n1 .venv/bin/yapf
#!/usr/local/Cellar/python/3.7.6_1/bin/python3.7
$ source .venv/bin/activate
$ yapf
Traceback (most recent call last):
  File "/Users/irvin/Projects/dotfiles/.venv/bin/yapf", line 5, in <module>
    from yapf import run_main
ModuleNotFoundError: No module named 'yapf'

Since yapf is not installed in the Homebrew Python's environment (based on the shebang), we get a ModuleNotFoundError.

See pypa/virtualenv#845 for more details. It seems that this is a bug in CPython/pip itself (supposed fix at python/cpython#9516), but there hasn't been movement on either CPython or pip to fix it.

Either way, blacklisting the __PYVENV_LAUNCHER__ environment variable before calling subprocess.Popen seems to be the fix adopted by most people in the interim; see wntrblm/nox#49 for an example.

irvinlim added a commit to irvinlim/dotfiles that referenced this pull request Feb 2, 2020
@sjkingo sjkingo merged commit 1acaf9d into sjkingo:master Feb 3, 2020
@sjkingo
Copy link
Owner

sjkingo commented Feb 3, 2020

Thanks for the PR! I have merged & release this now as 2.1.18.

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

Successfully merging this pull request may close these issues.

2 participants