81

I am using Poetry for the first time. I have a very simple project. Basically

a_project
|
|--test
|    |---test_something.py
|
|-script_to_test.py

From a project I do poetry init and then poetry install

I get the following

 poetry install
Updating dependencies
Resolving dependencies... (0.5s)

Writing lock file

Package operations: 7 installs, 0 updates, 0 removals

  • Installing attrs (22.2.0)
  • Installing exceptiongroup (1.1.0)
  • Installing iniconfig (2.0.0)
  • Installing packaging (23.0)
  • Installing pluggy (1.0.0)
  • Installing tomli (2.0.1)
  • Installing pytest (7.2.1)

/home/me/MyStudy/2023/pyenv_practice/dos/a_project/a_project does not contain any element

after this I can run poetry run pytest without problem but what does that error message mean?

1
  • 5
    Please show your pyproject.toml as well.
    – finswimmer
    Commented Feb 9, 2023 at 11:35

5 Answers 5

116

Check if your pyproject.toml contains something like:

    [tool.poetry]
    packages = [{include = "a_project"}]

Removing the line with packages = [{include = "a_project"}] helped in my case and should avoid including the root project. See documentation here.

If you're on poetry>=1.8, also make sure to have

[tool.poetry]
package-mode = false

in your configuration as stated here in the documentation here.

Edit: As this is getting some attention; also note the post by @bfontaine

0
68

This is probably because Poetry tries to install your project but does not find it (there’s no a_project module inside your directory). You can tell it not to install the root project with --no-root:

poetry install --no-root

Starting with Poetry 1.8, you can change the operating mode to tell Pypi not to treat your project as a package by editing the pyproject.toml:

[tool.poetry]
package-mode = false

(thanks to @amoralesc for the update)

1
  • 2
    This answer works very well if you are creating a Docker image for development purposes. I suspect this also should be the "Accepted" answer to the overarching question as well. Commented Apr 11, 2023 at 20:22
2

In my case I was using a wrong project name in

packages = [{include="abc_def_ghi"}]

I had used slashes instead of underscores.

1

My issue got away after pointed correct interpreter in PyCharm. Poetry makes project environment in its own directories and PyCharm didn't link that correct.

I've added new environment in PyCharm and select poetary's just created enviroment in dialogs.

-1

create a dir with_your_package_name that u find in the file and an empty __init__.py in project root

delete the poetry.lock and install again

1
  • with_your_package_name means a_project in this case? Commented Feb 10, 2023 at 1:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.