Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of __PYVENV_LAUNCHER__ environment variable?

Tags:

python

pip

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.

like image 808
Sherwood Wang Avatar asked Oct 12 '14 09:10

Sherwood Wang


People also ask

What is the purpose of Pythoncaseok environment variable?

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.

How do I set environment variables in environ?

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.


1 Answers

__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.

like image 52
Martijn Pieters Avatar answered Nov 15 '22 05:11

Martijn Pieters