I have a project structure like:
MyPackage
|
├──mypackage
| |
| ├── __init__.py
| |
| ├── config.py
| |
| ├── data_clean
| | ├── __init__.py
| | └── f1.py
| |
| ├── data_transform
| | ├── __init__.py
| | └── g1.py
| |
| └── stat_calc
| ├── __init__.py
| ├── s1.py
| └── command_line_interface.py # <- users will use this from cmd.exe
|
├── README.txt
|
└── setup.py
I need to be able to do python path/to/command_line_interface.py arg1
but when I do this I get ImportError: No module named 'stat_calc'
. Inside of command_line_interface.py
I have tried putting both:
import sys
sys.path.append('path/to/MyPackage')
and also:
import sys
sys.path.append('path/to/MyPackage/mypackage')
and also:
import sys
sys.path.append('path/to/MyPackage/mypackage/data_clean')
sys.path.append('path/to/MyPackage/mypackage/data_transform')
sys.path.append('path/to/MyPackage/mypackage/stat_calc')
but none of them worked. When I run all my stuff in my Pycharm Editor, without command line, my packages like stat_calc
and data_clean
import from each other using import mypackage.data_clean.f1
syntax and that seems to work fine, but running from command line doesn't work.I'm not sure what I'm doing wrong when trying to setup command line access. All of my init.py files are empty.