I am new to Python packages, and I am struggling to get something working.
I have 3 packages : engine
, ui
and db
. I'd like db
to be used from the other two packages. What is the correct way to do so?
I'd like not to install the db
package, since I am currently developing the 3 packages at the same time.
Thanks!
For the moment, I am trying to do so with imports of sibling packages, but it sucks so much that I'm not sure this is the correct way to do so. This question is closely related to tons of questions such as Relative imports in Python 3 or ValueError: attempted relative import beyond top-level package, but none of them has a valid, working answer for me :-(
Here's what I have so far:
src/
__init__.py # empty file (is it useful?)
db/
__init__.py # empty file
constants.py
ui/
__init__.py # empty file
index.py
engine/
...some stuff...
Here is index.py:
from .. import db
print(db.constants.stuff)
However, running cd ui && python3 index.py
or python3 -m index.py
fail with SystemError: Parent module '' not loaded, cannot perform relative import
When I tweak this project, I sometimes get yet other errors, such as ValueError: Attempted relative import in non-package
From what I read on https://docs.python.org/3/tutorial/modules.html, this should work, shouldn't it?
What am I doing wrong? What should I do to (do such a simple thing as) use a common package from two other packages?