简体   繁体   中英

When/how does Python use PYTHONPATH

I'm having some trouble understanding how Python uses the PYTHONPATH environment variable. According to the documentation, the import search path ( sys.path ) is "Initialized from the environment variable PYTHONPATH , plus an installation-dependent default."

In a Windows command box, I started Python (v.2.7.6) and printed the value of sys.path . I got a list of pathnames, the "installation-dependent default."

Then I quit Python, set PYTHONPATH to .;./lib; , restarted Python, and printed os.environ['PYTHONPATH']. I got .;./lib; as expected. Then I printed sys.path . I think it should have been the installation-dependent default with .;./lib; added to the start or the end. Instead it was the installation-dependent default alone, as if PYTHONPATH were empty. What am I missing here?

It always uses PYTHONPATH . What happened is probably that you quit python, but didn't quit your console/command shell. For that shell, the environment that was set when the shell was started still applies, and hence, there's no PYTHONPATH set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM