modifying sys.path on win98...?

Alex Martelli aleaxit at
Tue Jul 3 17:16:34 CEST 2001

"chajadan" <me at> wrote in message
news:3b40d94c.3665104 at
> I'm trying to update the sys.path for python on win98...
> I altered the registry, under local machine, seemingly correct. But
> when I access the sys.path to check it, my alterations don't show,
> even after rebooting.
> I can use sys.path.append, but the change only lasts until I close
> python. Then it reverts back to its original state.
> How do I make the alteration 'permanent' ?

You can write in PYTHONHOME (typically C:\Python21 on a Win98
installation of Python 2.1) a textfile with an arbitrary name
and extension .pth.  Such files are read and processed by on every run of Python (except when the run uses a
-S to explicitly bypass site installation, but then all bets
are off:-).  Blank lines, and lines starting with #, are
skipped.  Lines starting with import are executed.  All other
lines are added to sys.path, one directory per such line,
if the directory that a line names does actually exist.

So, to "permanently" add, say, directory "C:/Blippo" to your
sys.path, one simple way is (Python 2.1):

    import sys, os.path, time
    pth_file = open(os.path.join(sys.prefix, "Blippo.Pth"), w)
    pth_file.write("# created by on %s\n" %

assuming you want to do it in a Python script -- you can
also perfectly well do it with a text editor, of course:-).

After has finished preparing sys.path, it also
tries to import, so, if you need to,
you can further tweak the path at this point.  E.g.,
directories added by .pth files tend to go at the END
of sys.path -- if you need to have C:/Blippo right at
the START of the path (because it must shadow and hide
other directories on the path), you'd better see to it
in (or other custom script import'ed
from a .pth file, of course).

I think this is decently well documented in the library
reference (under module site).


More information about the Python-list mailing list