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

asked Nov 17, 2010 at 17:15

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

answered Nov 17, 2010 at 17:29
7
  • I already have the python path set to this: %PYTHONPATH%C:\PythonScripts\SharedPython and it's still not working. Commented Nov 17, 2010 at 17:54
  • @Ramy: That doesn't look right. output PYTHONPATH with echo %PYTHONPATH% and see what it contains Commented Nov 17, 2010 at 18:03
  • C:\Documents and Settings\ramy.abdel-azim>echo %PYTHONPATH% %PYTHONPATH%C:\PythonScripts\SharedPython Commented Nov 17, 2010 at 18:04
  • that seems to have done it. Windows environment variables are so annoying to me. Commented Nov 17, 2010 at 18:23
  • 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. Commented Nov 17, 2010 at 18:34
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.

answered Nov 17, 2010 at 17:29
3
  • what would the batch file look like and where would it be picked up/run? i.e. who calls the batch file? Commented Nov 17, 2010 at 17:58
  • 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. Commented Nov 17, 2010 at 18:03
  • 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. Commented Nov 17, 2010 at 18:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.