I know this question has been asked a lot, and I've read tens of blogs about the issue too, but there simply must be something I'm missing.
My understanding is that using the sys.path
method is not pythonic, so I'm trying to do this in the best way.
I have an app which has the following file structure:
application
├── db
│ └── db_setup.py
│ └── read_db.py
│ └── write_db.py
│ └── database.db
│
├── server
| └── server1.py
| └── server1.py
|
├── web
└── #contains all the files for a React web app
One of the servers is responsible for handling database requests so it needs access to the read and write python files.
I've tried each of the following in server1.py:
from db import read_db
import db
from db import read_db
from db.read_db import *
I've tried including an __init__.py
file in the db and server folders (in both, and in one but not the other for both) as well as doing relative imports using dot syntax (e.g. from .db import read_db
).
I will always get one of the following errors:
attempted relative import with no known parent package
or no module named
The only thing I can think of is that it's not possible to within an application like this define modules or packages that can import into others in the same application... but that just doesn't sound right.