1

When I enter echo $PYTHONPATH, it returns an empty string.

However, when I enter python -c 'import sys;print sys.path' I receive the following:

['', '/Users/adamg/src/lasagne/examples/src/lasagne', 
'/Users/adamg/anaconda/lib/python2.7/site-packages/six-1.10.0-py2.7.egg', 
'/Users/adamg/anaconda/lib/python27.zip', '/Users/adamg/anaconda/lib/python2.7',
'/Users/adamg/anaconda/lib/python2.7/plat-darwin',
'/Users/adamg/anaconda/lib/python2.7/plat-mac', '/Users/adamg/anaconda/lib/python2.7/plat-mac/lib-scriptpackages', 
'/Users/adamg/anaconda/lib/python2.7/lib-tk', 
'/Users/adamg/anaconda/lib/python2.7/lib-old', 
'/Users/adamg/anaconda/lib/python2.7/lib-dynload', 
'/Users/adamg/anaconda/lib/python2.7/site-packages', 
'/Users/adamg/anaconda/lib/python2.7/site-packages/Sphinx-1.2.3-py2.7.egg', 
'/Users/adamg/anaconda/lib/python2.7/site-packages/aeosa', 
'/Users/adamg/anaconda/lib/python2.7/site-packages/cryptography-0.8-py2.7-macosx-10.5-x86_64.egg', 
'/Users/adamg/anaconda/lib/python2.7/site-packages/setuptools-18.4-py2.7.egg'] 

and python3 python3 -c 'import sys;print(sys.path)'

['', 
'/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', 
'/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4', 
'/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', 
'/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', 
'/usr/local/lib/python3.4/site-packages']

Should I delete some of these? Further, what should I set $PYTHONPATH to so I can, by default, do scientific computing in Python 3.x?

14
  • 2
    Don't delete anything! You only need to set or change PYTHONPATH if you have modules installed somewhere other than the directories you have listed. Do you have a specific problem with scientific computing? Commented Dec 29, 2015 at 23:50
  • Yes. In trying out new IDEs like Rodeo and Pineapple, I can't find a module that works in the shell. I feel like there are a lot of conflicts in my installation. Commented Dec 29, 2015 at 23:54
  • Have you actually installed any scientific computing libraries for Python 3, or do you just have the Python 2 versions? The Python 2 versions aren't compatible with Python 3, even if you screw up your path so Python 3 sees those versions. Commented Dec 29, 2015 at 23:55
  • 1
    @Adam_G I've had the same problem with Rodeo. It has to be told which python executable to use - I think by default it picks /usr/bin/python or something, which is not what you want. With an anaconda installation you probably want /Users/adamg/anaconda/bin/python. The setting is in the preferences tab, lower right panel of Rodeo window. Commented Dec 30, 2015 at 0:07
  • 1
    Based on my own similar experience, your problem is most likely that your Rodeo python install and your shell python install (what you get typing python at the terminal) are not the same. Anaconda will be the installation with all the scientific computing packages, so you probably want the anaconda python I mentioned above. Also, if you've done any pip installs, they may have gone to the wrong python as well. People typically use conda to install packages in anaconda, not pip. Commented Dec 30, 2015 at 0:36

2 Answers 2

3

Module search path:

  • First it searches for a built-in module
  • Next it searches for the module in a list of directories given by sys.path, which is initialized from these locations:

    • The directory containing the input script (or current directory)
    • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH)
    • The installation-dependent default

How to alter sys.path:

  • sys.path.insert(_number_, '/whateverfilepath/')
  • Use 1 instead of 0 for number so that Python will look in the current working directory first
Sign up to request clarification or add additional context in comments.

Comments

1

You're just seeing your current working directory plus the path defaults from your site (Anaconda) installation. From the docs:

sys.path: A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.

As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH.

A program is free to modify this list for its own purposes.

Changed in version 2.3: Unicode strings are no longer ignored.

See also Module site This describes how to use .pth files to extend sys.path.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.