简体   繁体   中英

Python adding lots of things to PATH. How do I stop?

I'm finding that python is modifying my path in problematic ways -- in particular, it's pre-pending the path to my github development folder, which results in the wrong libraries being loaded.

In my terminal session, if I run echo $PATH I get:

~$echo $PATH
/Users/Nick/anaconda/bin:/usr/local/bin:/usr/bin:
/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin

Which is perfect. But when I launch python from that same terminal session (either as python or ipython ) and check my PATH from within python, I'm getting:

>>> print(sys.path)
['', '/Users/Nick/anaconda/lib/python3.4/site-packages/Cython-0.22.1-py3.4-
macosx-10.5-x86_64.egg', '/Users/Nick/github/pandas', 
'/Users/Nick/anaconda/lib/python34.zip', '/Users/Nick/anaconda/lib/python3.4',     
'/Users/Nick/anaconda/lib/python3.4/plat-darwin', 
'/Users/Nick/anaconda/lib/python3.4/lib-dynload', 
'/Users/Nick/anaconda/lib/python3.4/site-packages', 
'/Users/Nick/anaconda/lib/python3.4/site-packages/Sphinx-1.3.1-py3.4.egg',
'/Users/Nick/anaconda/lib/python3.4/site-packages/aeosa', 
'/Users/Nick/anaconda/lib/python3.4/site-packages/setuptools-18.0.1-py3.4.egg']

Where are these coming from and how do I stop them?

Thanks!

PATH has nothing to do with the Python module search path; that environment variable is used by your shell to find executables, instead.

You need to look at the PYTHONPATH variable here.

If that variable doesn't contain your extra elements, start Python with the -S command line switch to disable loading site.py ; it may be that the extra elements are set by a .pth file. Also see the site module documentation :

A path configuration file is a file whose name has the form name.pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path .

While $PATH seems like it may be used by Python, what you actually want to look at is your $PYTHONPATH -- which is used by the import machinery and logic.

You should look into using virtualenv ironments to control the pathing of Python module lookups.

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