I accidentally noticed that when a child process is launched with subprocess.Popen
, two environment variables named __PYVENV_LAUNCHER__
and _
are set to paths of the python interpreter and the script respectively. These two variables seem to affect the behavior of pip
. I wonder the exact meaning of them.
PYTHONCASEOK. This environment variable is used to ignore all import statements while calling the Python interpreter. In a Windows machine, it is used to find the first case-insensitive match in an import statement.
With the environ dictionary variable value of the environment variable can be set by passing the key in the dictionary and assigning the value to it. With setdefault a default value can be assigned to the environment variable. Bypassing the key and the default value in the setdefault method.
__PYENV_LAUNCHER__
is an implementation detail of the way a Python framework build on Mac works.
In a framework build (a special build that allows you to run GUI apps powered by Python), Apple places strict limits on what you can do with the process. To break out of those limitations, the Python binary is actually a wrapper that then launches the 'real' Python binary as a child process (the Resources/Python.app/Contents/MacOS/Python
binary in the same framework package).
To let the child process know what the path was that was used to launch the wrapper binary, the wrapper sets the __PYVENV_LAUNCHER__
environment variable, and the actual Python binary then uses that instead of argv[0]
(set by the OS). This is important in case of hardlinked copies of the launcher binary, such as those used in a virtualenv. Hence the name PYVENV
in the variable.
The variable really shouldn't leak out beyond the point it has done its job, so it is being removed from the environment once read in future Python releases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With