This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients chrullrich, davin, eryksun, ned.deily, paul.moore, pitrou, steve.dower, tim.golden, zach.ware
Date 2019-01-22.21:55:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1548194133.09.0.253843937071.issue35797@roundup.psfhosted.org>
In-reply-to
Content
> The current solution is the simplest one that ensures the most 
> compatibility for the least amount of risk, even though that 
> was not zero risk, as we've seen. 

How about making the py[w].exe launcher unset __PYVENV_LAUNCHER__ whenever it runs a registered version explicitly?

We could also modify the embedded-script (entry-point) launchers, which would be simpler if we had them in core instead of distlib. They could be updated to look for pyvenv.cfg. If found, it would override the shebang and set the __PYVENV_LAUNCHER__ environment variable. This would eliminate the interjected process in a 3.7.2 virtual environment, e.g. pip.exe -> python.exe (venv launcher) -> python.exe (installed) would become pip.exe -> python.exe (installed). More importantly, it would unset __PYVENV_LAUNCHER__ in case it's not a virtual environment script. 

This way running pip.exe for an installed Python won't end up installing into a virtual environment, as can happen now in 3.7.2. For example:

    >>> print(os.environ['__PYVENV_LAUNCHER__'])
    C:\Temp\env37\Scripts\python.exe

    >>> import requests
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'requests'

    >>> pip = 'Scripts\\pip.exe'
    >>> out = subprocess.check_output('{} install requests'.format(pip))

    >>> import requests
    >>> requests.__version__
    '2.21.0'

Note that "Scripts\\pip.exe" in a CreateProcess command line gets resolved first relative to the application directory, before trying the current directory, system directories, and PATH directories.
History
Date User Action Args
2019-01-22 21:55:35eryksunsetrecipients: + eryksun, paul.moore, pitrou, tim.golden, ned.deily, zach.ware, steve.dower, chrullrich, davin
2019-01-22 21:55:33eryksunsetmessageid: <1548194133.09.0.253843937071.issue35797@roundup.psfhosted.org>
2019-01-22 21:55:33eryksunlinkissue35797 messages
2019-01-22 21:55:32eryksuncreate