KansaiRobot
KansaiRobot

Reputation: 10022

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

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?

Upvotes: 84

Views: 66650

Answers (5)

stroblme
stroblme

Reputation: 1366

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. Or when you're setting up a new project, simply run

poetry install --no-root

as mentioned by @bfontaine .


Old solution:

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.

Upvotes: 119

bfontaine
bfontaine

Reputation: 19859

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)

Upvotes: 70

Rasitha Gamage
Rasitha Gamage

Reputation: 61

In my case I was using a wrong project name in

packages = [{include="abc_def_ghi"}]

I had used slashes instead of underscores.

Upvotes: 2

Vodyanikov Andrew
Vodyanikov Andrew

Reputation: 399

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.

Upvotes: 1

Marco Disco
Marco Disco

Reputation: 565

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

Upvotes: -1

Related Questions