[Tutor] question about sys.path and importing
kent37 at tds.net
Tue Oct 3 20:38:04 CEST 2006
Dick Moores wrote:
> This morning I was sternly warned by Wingware support not to leave my
> module of useful functions in Python25\Lib. So I put it in a
> subfolder in site-packages I named "mine". Importing of or from that
> module, mycalc.py goes well, to my surprise, because of
> >>> import sys
> >>> [x for x in sys.path if "site-packages" in x]
> in which "mine" isn't included, even though other folders in site-packages are.
> Can someone explain this, please?
If the program that does the import is also in site-packages\mine, that
would explain it. When you run a script its directory is added to sys.path.
Normally you will need to either
- make 'mine' be a package, by creating an empty file named
site-packages\mine\__init__.py, and changing your imports to include the
package name (from mine import mycalc), or
- add site-packages\mine to sys.path, maybe by creating a .pth file.
Gee, maybe I should just invite you over and we can talk ;)
More information about the Tutor