tags:

views:

1527

answers:

7

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?

+2  A: 

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
+6  A: 

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
Lucas Jones
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
As has been said, Python defines its own "sys.path" at runtime. The PYTHONPATH is mainly supplemental.
Lucas Jones
+4  A: 

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
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
A: 

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

MStodd
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
A: 

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  A: 

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
A: 
mystoo