PYTHONPATH in Windows XP

Contents

The PYTHONPATH variable

Editing the Windows registry

References

Intro

16th January 2008

After running into a series of difficulties while trying to compile a Pyrex package comprising of several modules, I ran into this brute force method to make sure all the frisky little spirits involved in my magic spell, namely the Python interpreter, the Pyrex distutils module and his pal, MinGW's gcc compiler, are able to find the necessary files: stick the package's directory right in the Python path environment variable.

This rudimentary but allegedly ingenious notion led to considerable frustration, as Windows XP's system manager failed to cooperate with my efforts: adding a PYTHONPATH environment variable did not really modify the Python path, as seen from the sys.path variable.

As customary, a search through the web eventually rewarded me with a couple of pointers shared by better sorcerers than I, whose knowledge I parrot below, in the hope that it may aid others as it did me.

Editing the Windows registry

16th January 2008

It turned out that I was lacking the means of directly modifying the variable in question at that daunting cavern of weirdness known as the Windows registry. Here follows the recipe:

  1. Open the "Run..." dialog box (at the Start Menu) and invoke regedit
  2. Browse under HKEY_LOCAL_MACHINE and look for the appropriate Python folder. Therein lies a key called PythonPath.
  3. Right-click on PythonPath to add a new key. Name it appropriately.
  4. Right-click on the "Default" value name in order to modify it.
  5. Fill in the value data text box with the full directory path.

Pronto! The package's directory is now in the path and the modules may be invoked directly from the Python interpreter. Be warned: name your modules in a sensible fashion or suffer the consequences.

References

16th January 2008

Some related material: