sys.path vs os.environ['POST']

Gerhard Häring gh at ghaering.de
Wed May 21 05:16:58 EDT 2003


Achim Domma wrote:
> "Gerhard Häring" <gh at ghaering.de> wrote:
>>sys.path are the directories Python searches for modules in when you try
>>to import one. To see the Python import mechanism at work, you can start
>>Python with "python -v" and then for example "import smtplib" at the
>>interactive prompt.
>>
>>os.environ['PATH'] refers to the PATH environment variable, which is a
>>list of directories the operating system tries to find an executable in
>>if you try to start an application without an absolute or relative path,
>>i. e. something like "notepad" or "ls".
> 
> Thanks, that explains the behavior and solves all my problems. I will hold
> my Dlls in a subfolder of my module, called 'DLLs'. In my __init__.py I will
> do something like this:
> 
> import sys,os
> from os.path import split, join
> path = join(split(__file__)[0],'DLLs')
> sys.path.append(path)
> os.environ['PATH'] += ";"+path
> 
> Is that ok, or is there something bad with modifying sys.path and
> os.environ['PATH'] in an __init__.py?

That should work fine. What would also work is to put the DLLs in the 
same directory as the Python extension module (.pyd). Windows will 
search there automatically.

-- Gerhard





More information about the Python-list mailing list