I have the following file structure...
 > Boo
    > ---modA
    > ------__init__.py
    > ------fileAA.py
    > ---modB
    > ------__init__.py
    > ------fileBB.py
When inside fileBB.py I am doing
from modA.fileAA import <something>
I get the following error:
from modA.fileAA import <something>
ModuleNotFoundError: No module named 'modA'
Note that the __init__.py files are empty and using Python 3.
What am I missing or doing wrong here?
This is almost certainly a PYTHONPATH issue of where you're running your script from.  In general this works:
$ ls modA/
fileAA.py  __init__.py
$ cat modA/fileAA.py 
x = 1
$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from modA.fileAA import x
>>> x
1
You can look at sys.path to inspect your path.
main_package
├── __init__.py
├── modA
│   ├── fileAA.py
│   └── __init__.py
└── modB
    ├── fileBB.py
    └── __init__.py
Have an __init__.py in the root directory and then use import like
from main_package.modA.fileAA import something
Run using a driver file inside main_package then run, it'll work.
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