Reputation: 3034
I have this directory structure:
my_project/
site/
__init__.py
app.py
main.py
main.py contains this:
import site.app
print('Success')
Get this error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import site.app
ImportError: No module named 'site.app'; 'site' is not a package
Renaming "site" to any other name, this works correctly. Example:
$ mv site/ foo/
$ echo -e "import foo.app\nprint('Success')" > main.py
$ python main.py
Success
$
Is "site" a special package name? Why? How do I get around it?
Upvotes: 1
Views: 3879
Reputation: 251578
site
is a standard library module. The way to get around it is don't name your package that, just like you wouldn't name it math
or sys
or itertools
. If you want my_project
to be a package, make it a package, make it a package by giving it an __init__.py
. You don't want to create a top-level package called site
.
Upvotes: 2