I'm trying to create a python package, and I have have trouble with the imports. My code works as expected when running it, but when I install the package using poetry and import it in another script, I have a ModuleNotFoundError.
My file structure is the following :
git_repo
| myapp
| |--__init__.py
| |--mainscript.py
| |--library
| | |--__init__.py
| | |--module.py
My file mainscript.py
imports the module.py
because there are some utility functions :
from library import module
When I execute the mainscript, no problem. However, when installing myapp
using poetry install
and trying to import it in a python shell :
> python
>>> import myapp.mainscript
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\path\to\mainscript.py", line 5, in <module>
from library import module
ModuleNotFoundError: No module named 'library'
Is there a mechanic I don't understand with the imports ? Do I have to write something in the __init__.py
files ?
Thanks in advance for your help