jaraco / pip-run

pip-run - dynamic dependency loader for Python
MIT License
135 stars 20 forks source link

PYTHONPATH leaks into subprocesses #27

Closed jaraco closed 5 years ago

jaraco commented 6 years ago

The way rwt works, it sets PYTHONPATH when invoking its child Python process, to present the new packages to it. And if that Python process invokes subprocesses, they inherit the environment by default. Sometimes, this inheritance is useful, because especially if the subprocess is the same Python (sys.executable). Other times, it's an impediment.

Consider the case where rwt is invoked on Python 3 and loads a number of libraries, but then the subprocess invokes a Python 2 subprocess in another environment. Now that Python 2 subprocess finds itself trying to import modules that were installed and configured for Python 3, and hilarity ensues.

jaraco commented 6 years ago

I'm not sure there's a solution for this, especially because it's not obvious when this inheritance would be useful or not. It's almost the responsibility of the child process to clear that value or not pass it through when it's not appropriate.

I was entertaining the idea of building on the _inject_sitecustomize behavior, but currently that behavior is only on Python 3.2 and earlier, and I consider that behavior a little brittle (as it would mask other sitecustomize modules in the path, unless we took on the additional task of running the next sitecustomize module).