Ramy
Ramy

Reputation: 21261

how to set up environment variables for python

On WinXP sp2 I'd like to have a directory of modules that other python scripts will be using called "SharedPython" in the same directory as my python scripts. so, basically:

/pythonScripts
/pythonScripts/SharedPython

as well as other python scripts on the same level as the SharedPython directory.

when I run

print sys.path

I get the following output:

C:\WINDOWS\system32\python25.zip
C:\Python25\DLLs
C:\Python25\lib
C:\Python25\lib\plat-win
C:\Python25\lib\lib-tk
C:\Python25
C:\Python25\lib\site-packages

I don't know what environment variable controls this and, in fact, I don't see one that contains all these directories. So, a.)how do I determine which environment variable contains this list of dirs? and b.)can I just add the aforementioned SharedPython dir to that list?

I've tried setting PYTHONPATH to the following: %PYTHONPATH%C:\PythonScripts\SharedPython

Upvotes: 1

Views: 2760

Answers (2)

Eli Bendersky
Eli Bendersky

Reputation: 273366

You need the PYTHONPATH env var. The dirs listed in it are prepended to sys.path.

The correct way to setup PYTHONPATH in your case is:

set PYTHONPATH=%PYTHONPATH%;C:\PythonScripts\SharedPython

Note the semicolon between the second % and the C:\

Upvotes: 5

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798456

Those paths are added by the site module; do not change this module, but rather create a batch file that adds your paths in %PYTHONPATH% and then runs the script.

Upvotes: 1

Related Questions