Newbie thwarted by sys.path on Vista

Christian Heimes lists at cheimes.de
Sun Aug 2 09:08:25 EDT 2009


Michael M Mason wrote:
> I'm running Python 3.1 on Vista and I can't figure out how to add my own 
> directory to  sys.path.
> 
> The docs suggest that I can either add it to the PYTHONPATH environment 
> variable or to the PythonPath key in the registry.  However, PYTHONPATH 
> doesn't exist, and updating the registry key has no effect (and in any case 
> the contents aren't the same as sys.path).
> 
> So where does sys.path get its value from, and how do I change it?

You can use my PEP 370 (http://python.org/dev/peps/pep-0370/) and a .pth 
file to extend the search path for modules.

 >>> import os
 >>> import site
 >>> site.USER_SITE
'/home/heimes/.local/lib/python2.6/site-packages'
 >>> if not os.path.isdir(site.USER_SITE):
...     os.makedirs(site.USER_SITE)
...
 >>> pth = open(os.path.join(site.USER_SITE, "michal.pth"), "w")
 >>> pth.write("C:/Users/Michael/Code/Python\n")
 >>> pth.close()

Restart Python, your custom search path should be in sys.path.

Christian




More information about the Python-list mailing list