Newbie thwarted by sys.path on Vista
Dave Angel
davea at ieee.org
Sat Aug 1 20:29:12 EDT 2009
Michael M Mason wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">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?
>
sys.path gets its values from several places. The ones I think I know
of are:
current directory (which uses "" rather than the expected ".")
directories listed in PythonPath environment variable
Windows-system directory
relative to the executable (python.exe or pythonw.exe) that's
actually running
relative to the user directory (docs&settings/username/Application
Data ....
If there's no PythonPath variable, it just uses those other items. I
have no idea what it gets from the registry entries.
Anyway, I'd suggest adding it to PythonPath, and if it's empty, just
create it with the directory you need.
I'm hoping you know you can also add to sys.path directly during script
initialization. It's just a list, and is writeable.
More information about the Python-list
mailing list