1

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

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

7 Comments

I already have the python path set to this: %PYTHONPATH%C:\PythonScripts\SharedPython and it's still not working.
@Ramy: That doesn't look right. output PYTHONPATH with echo %PYTHONPATH% and see what it contains
C:\Documents and Settings\ramy.abdel-azim>echo %PYTHONPATH% %PYTHONPATH%C:\PythonScripts\SharedPython
that seems to have done it. Windows environment variables are so annoying to me.
Tip: You can make the change permanently by right-clicking on My Computer and selecting Properties. Select the Advanced tab in the dialog box that appears and then click on the Environment Variables button. Aanother dialog box will appear and in that you can define the PYTHONPATH variable to be what you want.
|
1

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.

3 Comments

what would the batch file look like and where would it be picked up/run? i.e. who calls the batch file?
It would contain a SET command to set the variable, and a call to the Python script/executable. It can be put anywhere, but somewhere in %PATH% would be convenient. It would be called by the user or by a shortcut.
that seems like a lot of overhead if I have to create a batch script that will update the >PATH and then call the script. i'd rather have the scheduled task call the script directly as I have for most of my other python scripts.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.