Skip to content Skip to sidebar Skip to footer

Can't Find My Pythonpath

I'm trying to change my PYTHONPATH. I've tried to change it in 'My Computer' etc, but it doesn't exist there. I searched in the registry in some places, and even ran a whole search

Solution 1:

At runtime, you can change it with:

import sys
sys.path.append('...')

In My Computer, right-click Properties (or press Win-Break), System tab, Environment Variables, System. You can add it if it's not already there.

Finally, in the CMD prompt:

set PYTHONPATH C:\Python25\Lib;C:\MyPythonLib

Or in bash:

PYTHONPATH=/usr/share/python/lib:/home/me/python
export PYTHONPATH

Or, more succinctly:

exportPYTHONPATH=/home/me/python

Solution 2:

Python does some stuff up front when it is started, probably also setting that path in windows. Just set it and see, if it is changed in sys.path.

Setting environment variables in the Python docs say:

My Computer ‣ Properties ‣ Advanced ‣ Environment Variables

Solution 3:

You can add it under "My Computer" if it doesn't exist. PYTHONPATH just adds to the default sys.path.

On unix/linux/osx you can:

$ exportPYTHONPATH=/to/my/python/libs

You can also use .pth files to point to libraries:

http://docs.python.org/library/site.html#module-site

And of course:

import sys
sys.path.append('/path/to/libs/')

Also, check out virtualenv for managing libraries for multiple projects.

Solution 4:

Here's how I solved it.

First, get the current path. There's a lot more there than I expected.

import sys
print';'.join(sys.path)

Copy that result to the clipboard. Go to My Computer and create the new environment variable PYTHONPATH, and for the value paste from the clipboard. Modify as necessary.

Solution 5:

MacOS 10.5.8, Python 2.6, Eclipse+Pydev 1.5.7

  1. Python installation's site-package is, for example:

    /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
  2. create symlinks YOUR LIBRARY inside into site-package, for example:

    cd /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
    ln -s /path/to/YOUR/LIBRARY/ YOUR_LIBRARY_NAME
    
    Now You can use in commandline:
    import YOUR_LIBRARY_NAME 
  3. run Eclipse with Pydev, go to Preferences->Pydev->Interpreter Python

  4. remove Your Python interpreter record, if exists;

  5. click New and add Python 2.6 interpreter path, for example:

    /Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
    
  6. notice, that Eclipse Pydev display Python System Library, accept that

  7. in Library section click New Folder and write path to YOUR LIBRARY, for example:

    /path/to/YOUR/LIBRARY/
  8. click Apply - it is essential, because Eclipse Pydev built now his own "library map", when this operation finish - click [OK]

  9. close Eclipse

  10. run Eclipse again - now You should use in Pydev:

    import YOUR_LIBRARY_NAME 

Post a Comment for "Can't Find My Pythonpath"