I'm guessing this may already be answered, but all my searches are turning up other import issues. Then again, perhaps I just don't know the proper terms to search for.
If I create a package with a module, it seems I can use from mypackage import mymodule
to use mymodule
in my code. However, I can't use import mypackage
and then use mypackage.mymodule
. With this I get a AttributeError: 'module' object has no attribute 'mymodule'
error. Why is this and how do I set it up so I can use this?
My package structure is shown below. All the __init__.py
s are empty.
myproject
__init__.py
mypackage
__init__.py
mymodule.py
mymain.py # Doing the importing.
Submodules are not implicitly imported. You will need to import
.mymodule
inmypackage/__init__.py
unless you explicitly want to importmypackage.mymodule
.