poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Notebooks/script don't recognize project package

Open jralfonsog opened this issue 5 years ago • 4 comments

  • [x] I am on the latest Poetry version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Linux Mint 19.3
  • Poetry version: 1.1.5
  • Link of a Gist with the contents of your pyproject.toml file: Link

Issue

Hello there.

I'm trying to use my project package from notebooks or some scripts placed outside of the source code folder. My project structure is the following:

├── notebooks │   └── Untitled.ipynb ├── poetry.lock ├── pyproject.toml ├── scripts │   ├── init.py │   └── hello.py ├── source │   ├── init.py │   └── utils.py ├── tests │   └── init.py └── zip_project.py

After running poetry install, If I try to import anything from source, whether it's from the notebook or from that hello.py script, it can't find the source module. It works if I do poetry run python scripts/hello.py, but it shouldn't be the solution as it would still not work for the notebooks. I use pyenv for python version management, in case it is relevant.

I'm pretty sure I've done this before, but I don't know if there's something I'm doing wrong.

jralfonsog avatar Mar 16 '21 03:03 jralfonsog

After checking out this, I've tried to run "poetry add ./source/", but got the following error:

TypeError

expected string or bytes-like object

at ~/.poetry/lib/poetry/vendor/py3.7/poetry/core/utils/helpers.py:27 in canonicalize_name 23│ canonicalize_regex = re.compile(r"[-]+") 24│ 25│ 26│ def canonicalize_name(name): # type: (str) -> str → 27│ return canonicalize_regex.sub("-", name).lower() 28│ 29│ 30│ def module_name(name): # type: (str) -> str 31│ return canonicalize_name(name).replace(".", "").replace("-", "")

jralfonsog avatar Mar 16 '21 18:03 jralfonsog

If init.py is supposed to be __init__.py then that's no longer necessary in Python 3. You can check the docs on how Poetry can find your non-standard modules. Also you need to replace the underscores in your pyproject.toml to dashes (click here to see what I'm referring to).

kasteph avatar Mar 25 '21 16:03 kasteph

Hi, @stephsamson, and thanks for your help.

After checking again the docs, and trying my best, I keep getting a "Directory {} does not seem to be a Python package" message every time I try to run poetry update.

The last pyproject.toml is in the updated gist.

I've tried with or without __init__ files. I've checked with a package named mlflow_sqlite_template as well, without luck.

jralfonsog avatar Mar 27 '21 02:03 jralfonsog

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Mar 02 '24 10:03 github-actions[bot]