Poetry install on an existing project Error "does not contain any element"
Asked Answered
L

5

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?

Legman answered 9/2, 2023 at 11:8 Comment(1)
Please show your pyproject.toml as well.Gehrke
F
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

Fairley answered 16/2, 2023 at 11:8 Comment(0)
B
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)

Bronchiectasis answered 13/2, 2023 at 11:14 Comment(1)
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.Ruby
B
2

In my case I was using a wrong project name in

packages = [{include="abc_def_ghi"}]

I had used slashes instead of underscores.

Brownie answered 23/2 at 10:1 Comment(0)
B
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.

Breckenridge answered 16/2, 2023 at 9:56 Comment(0)
J
-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

Jeremiah answered 9/2, 2023 at 13:44 Comment(1)
with_your_package_name means a_project in this case?Legman

© 2022 - 2024 — McMap. All rights reserved.