Reputation: 390
I have a Python project (python 3.6) with a rather simple package structure. My goal is to have a package containing modules which are reused across other packages. Here is the structure:
my_project
├── /docs
├── /src
│ ├── __init__.py
│ ├── /common
│ | |── __init__.py
│ | |── common_module.py
│ ├── /packageA
│ | |── __init__.py
│ | |── modA.py
The problem is that when I do the following inside modA.py
:
from src.common import common_module as cm
I get the following error: ModuleNotFoundError: No module named src.common
What I have tried so far is
https://docs.python.org/3/tutorial/modules.html
export PYTHONPATH=<path_to_project>/src
__init__.py
inside /my_project
as wellsys.path
that was said to not a good solution even if it would work.None of these worked and I have been struggling with this problem for a while now so any suggestion would be appreciated.
Upvotes: 0
Views: 351
Reputation: 521
Yes you should put __init__.py
in project
,
then export PYTHONPATH = <LOCAL_PATH_TO_...>/project
Upvotes: 1
Reputation: 33335
In order for this import to work, PYTHONPATH would need to be .../my_project
, not .../my_project/src
.
Upvotes: 2