importpython-packagingpython-poetry

Poetry local package importation Module not found


I just start learning Poetry.

I am trying to import a local package in a poetry project.

This is the structure of the project:

MyProject
    myproject
       __init__.py
    tests
       __init__.py
      import_test.py
poetry.lock
pyproject.toml

the project I am trying to import has the same structure

My_Package
    my_package
       __init__.py
    tests
       __init__.py
      my_package.py
poetry.lock
pyproject.toml

In the package, I have a simple function that sums two integers.

I add the package to the project with command line: poetry add --editable ../My_Package

Yet, when I try to import it, the module isn't found.

I tried:

from my_package.tests import sum
sum(1+1)

and

import My_Package
My_Package.tests.sum(1+1)

I found this issue Packages installed with Poetry fail to import and fix it.

Yet still have the error.


Solution

  • Packages in tests aren't imported, I try again from stratch with the module in the folder "package" and then import it in a new project