I am getting a ModuleNotFoundError
in Python 3 when trying to import a package containing an __init__.py
that imports a variable from one of the package's modules.
My project structure is:
project/
test.py
package/
__init__.py
modu.py
modu.py:
value = 99
__init__.py:
from modu import value
test.py
:
import package
print(package.value) # or 'print package.value' for Python 2
When I run test.py
using Python 2, everything works. But when I run with Python 3, I get a ModuleNotFoundError: No module named 'modu'
. I am running from the project/
directory.
Can anyone explain why this is happening? Thanks.
Because Python3 expect absolute path for modules:
__init__.py
:
from package.modu import value
Works on both versions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With