Python Win installations and PYTHONPATH Confusion (WAS: Re: Python Path Blues)

Tim Peters tim.one at home.com
Sun Aug 19 18:13:13 EDT 2001


[Maan M. Hamze]
> What is important here is that this can be a BIG turn-off for beginners.
> It took me more than a day of tinkering with the registry while trying to
> make DCOracle2 and mxODBC packages for Python run correctly.

I haven't tried either.  Did their docs tell you to do this?

> Then I discovered it was all a matter of adding PYTHONPATH into the
> environment [under Windows]

That's one way to get it to work <wink>.

> ...
> 1.  Upon installing Python (PythonWin or the regular Python
> distribution for Windows), the registry itself is updated with the
> lib path,

It is, but please note that Python never *looks* at this setting in normal
operation.  It's there for the esoteric benefit of advanced Windows uses
that end up calling Python as a side-effect of doing something else.
Normally, you click on a .py file, or run Python from a DOS prompt directly,
and then Python doesn't even look at the registry.

> but NO PYTHONPATH setting is created in the environment.

In normal operation, it isn't needed.  In abnormal <wink> operation, the
registry is used.  PYTHONPATH isn't needed for anything we distribute, so of
course we don't set it.

> This is MISLEADING, since it appears that every other thrid party
> package is using this environment setting.

distutils manages to install things without mucking with PYTHONPATH, and
that's how it should be.

> If it is surprising Tim Peters :) I do not know how new comers to
> Python would figure something like this out.

The installation instructions that come with a package should explain how to
install it.  Sounds like you hit some bad luck.  I'm surprised by PYTHONPATH
because I always *expect* it to override everything else entirely, but it
doesn't (see below) -- there's simply too much magic for my tastes.

> 2.  I noticed that Python for Win installation adds Class ID's to the
> default Library paths in the registry.  Why?
> ...

Have to leave this one to ActiveState, but it doesn't sound like it's
causing you a problem.

> 3.  All this is leading to a PYTHONPATH setting in the registry, and a
> PYTHONPATH setting in the environment.  Do they have to be in synch?

No, but you shouldn't normally muck with either of them.  The PYTHONPATH
envar, if it's set, is always *added* to all other paths Python deduces.
The registry setting is used only in desperation, if Python is invoked in
such a way that it can't figure out where python.exe lives (this can happen,
e.g., if Python is effectively embedded via COM, and the Python DLL in the
system directory is the part of Python that's first activated -- then Python
resorts to the registry to find its libraries, as it's got no other clue).





More information about the Python-list mailing list