Sunday, January 31, 2010

setting paths for python on windows

1. Finding the python executable (python.exe). Add the directory to the windows environment variable "Path":
- right-click on "My Computer" > Properties > Advanced (tab) > Environment Variables (button).
- double-click on "Path" variable (in the System Variables box); click "Edit" button, and add directory containing python.exe (e.g. C:\Python26\)

Once this is done, should be able to run python by typing "python" in the command shell (cmd.exe).

2. Add directories to python search path (so that, e.g., import will find it). Add to the PYTHONPATH environment variable in the Windows registry:
- run regedit.exe (Start Menu > Run...)
- navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\\PythonPath\
- right-click on the "PythonPath" folder and choose "New Key". Give the key a meaningful name (e.g. PetersGeneralPythonFiles), since you may want to maintain several keys.
- right-click on the newly-created Default entry and enter the desired directory(ies) as its value.

Import statements for files in this path should now work when python is run from any location.

No comments:

Post a Comment