[Tutor] possible import locations
Kent Johnson
kent37 at tds.net
Wed Jan 17 12:07:19 CET 2007
Andre Engels wrote:
> Is it possible to see from a python program where it searches for
> possible imports? Is it possible to import from another location than
> those? (Of course with an "if so, how" attached).
>
> The issue is that the company I work for is switching providers. With
> the old provider (as well as in my local setting), Python automatically
> searched for imports in the current directory (the one where the program
> was run). With the new one, this does not seem to be the case, so I am
> getting ImportErrors all over the place.
sys.path is a list of locations that will be searched for imports. You
can add new entries to it with the usual list operations.
If you want to add '.' to sys.path always you could do this in a
sitecustomize.py module.
- Create a directory Lib\site-packages if it doesn't already exist
- Create a file site-packages\sitecustomize.py
- Put your custom startup stuff in sitecustomize.py
Is your new provider using a different OS? I remember a discussion long
ago about the current directory being in sys.path or not and it seemed
to vary depending on OS.
Kent
More information about the Tutor
mailing list