Adding paths to sys.path permanently, and another problem...
jeff at ccvcorp.com
Thu Dec 16 22:16:57 CET 2004
Lenard Lindstrom wrote:
>Amir Dekel <adekel at ort.org.il> writes:
>>I have two problems:
>>1. How can I keep my changes in sys.path after closing the interpreter?
>Saving sys.path changes between interpreter runs would be more involved.
>On Windows Python loads the initial module search path from the registry.
>Python's registry entries are made during installation and are left alone
>afterwards. Changing these entries is probably not a good idea. But
>if you need sys.path persistence I can try writing an example that does
>it automatically using the atexit module and a history file.
Not only can one modify the environment variable PYTHONPATH, but one can
also use a .pth file. Under windows, when the interpreter starts up it
will search its default sys.path for any files with extension .pth; if
it finds any, then it will use each line of those files as a directory
to add to sys.path. Thus, if you drop a mymodule.pth file in
site-packages, which contains a list of the directories you're
interested in, sys.path will automatically be amended for you every time
More information about the Python-list