Question

I am running a script that explicitly sets the PYTHONPATH to avoid naming collisions. However, even if I say os.environ['PYTHONPATH'] = '', it looks as though the system is still able to find my old path that "lives" outside the script.

How is my system able to see the old PYTHONPATH even after I explicitly set it to a new one?

Was it helpful?

Solution

The PYTHONPATH environment variable is parsed at startup and inserted into sys.path. If you need to adjust the path from within your Python code, manipulate sys.path, not PYTHONPATH.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top