12

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 for the word 'PYTHONPATH', but to no avail.

However, it Python I can easily see it exists. So where is it?

Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
R S
  • 11,359
  • 10
  • 43
  • 50

10 Answers10

11

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:

export PYTHONPATH=/home/me/python
Lucas Jones
  • 19,767
  • 8
  • 75
  • 88
  • 2
    This is not helping - the PYTHONPATH exists already, I just don't know where it is. If I write it, I will maybe deleted whatever is written there... – R S May 13 '09 at 18:56
  • 2
    As has been said, Python defines its own "sys.path" at runtime. The PYTHONPATH is mainly supplemental. – Lucas Jones May 13 '09 at 18:58
  • The "export PTYHONPATH" was missing for me, "export THANKS"! – Eduardo Feb 15 '13 at 10:37
6

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
wr.
  • 2,841
  • 1
  • 23
  • 27
5

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:

$ export PYTHONPATH=/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.

jsamsa
  • 939
  • 7
  • 12
  • 1
    This is not helping - the PYTHONPATH exists already, I just don't know where it is. If I write it, I will maybe deleted whatever is written there... – R S May 13 '09 at 18:56
3

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.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
1

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 
mystoo
  • 11
  • 1
1

And, as with all good things in life, you can find it in the documentation: http://docs.python.org/install/index.html#modifying-python-s-search-path

MLCoder
  • 41
  • 2
0

I had same problem and oliver-zehentleitner's answer in github solved my problem. He said: Maybe You install package with pip for python2 and run with python3, just try to install with pip3 or python3 -m pip install python-binance and then run your script again.

I hope this can solve yours too.

Mehr
  • 1
  • 1
0

When you use Python it can be in a few places, because lots of applications install it by themselves. for example, if you install GIMP, it installs Python by itself. when you try config your Python you see nothing happened after changes. it is because your OS uses the first Python it finds and it can be anywhere. To solve the problem: please add your Python link to the PATH (environment variables) and move it to the top, then OS starts top-to-down PATHs to find Python, it will find the Python that you install for development.

starball
  • 20,030
  • 7
  • 43
  • 238
Mehr
  • 1
  • 1
0

What's it set to? Have you tried creating a PYTHONPATH environment variable?

MStodd
  • 4,716
  • 3
  • 30
  • 50
  • It's set to quite a lot of libraries that are installed. I haven't changed it since I'm afraid that if I write it, I will maybe deleted whatever is written there... – R S May 13 '09 at 18:57
0

You need modify your environment variables. How to do this depends on which version of Windows you have.

If the PYTHONPATH variable doesn't exist, you have to create it. It might not exist if you haven't already created it.

BernzSed
  • 1,129
  • 8
  • 9