Permanently Adding A Directory to Pythonpath

Jason Cunliffe jasonic at nomadicsltd.com
Tue May 29 01:10:21 EDT 2001


> > I would like to know how to add a directory to my Pythonpath
permanently.
> I
>
> Simplest may be to have, in your PYTHONHOME directory (for
> example, on Windows, D:\Python21 if you have Python 2.1 and
> have chosen to install it there, as it its default), a text
> file with any name and extension .PTH, listing, one per line,
> the path of directories you want to be added to sys.path.

As best I can tell, there appear to be at least 4 ways on Win98 to add to
the PythonPath permanently. In descending order towards clearest and sanest
[imho] these are:


4.  Messing directly with the Registry

3.  Appending a line to autoexec.bat
    SET PYTHONPATH=C:\a...;C:\...;C:\..

2.  Using PythonWin 'Edit Python Path' feature

1.  Adding a .PTH file as suggested above

Perhaps it is just me, but it it seems this is one FAQ of Python on Win32
which could be much more clearly addressed for newbies and everyone.

The .PTH solution makes the most sense becuase it is legible and not
confused with other information somewhere in Windows guts. It appears to be
the only one which is portable. But unfortunately its often not well
mentioned in intro texts.

Python is mostly beautifully portable. So why doe standard distibutions not
include a little module of generic friendly commands to manage PYTHONPATH
the same way for all systems. This should handle temporary interactive needs
as well as more durable ones by putting basic wrapper functions using the
.PTH feature. It would help standardize moduel distribution even further.

For example:

import sys

sys.path.addPermanent("new_directory_name")      # adds to to .PTH
sys.path.deletePermanent("old_directory_name ")  # removes from .PTH
sys.path.suspendPermanent("some_directory_name") # only hide for this
session

Not doubt there is nicer syntax you can think of..

Am I missing something here?

thanks

./Jason





More information about the Python-list mailing list