gdm
gdm

Reputation: 7978

Poetry No File/Folder for Package

I have a simple project layout

myproject on ī‚  main [$!?] is šŸ“¦ v1.0.0 via īœ˜ v18.14.0 via šŸ v3.10.9 
āÆ tree -L 1
.
ā”œā”€ā”€ build
ā”œā”€ā”€ deploy
ā”œā”€ā”€ Dockerfile
ā”œā”€ā”€ poetry.lock
ā”œā”€ā”€ pyproject.toml
ā”œā”€ā”€ README.md
ā”œā”€ā”€ scripts.py
ā””ā”€ā”€ src

The pyproject.toml is:

[tool.poetry]
name = "myproject"
version = "0.1.0"
description = ""
authors = [""]

[tool.poetry.scripts]
test = "scripts:test"

The scripts.py is:

import subprocess

def test():
    """
    Run all unittests.
    
    """
    subprocess.run(
        ['python', '-u', '-m', 'pytest']
    )
if __name__ == '__main__':
    test()

When I run poetry run test:

myproject on main [$!?] is šŸ“¦ v1.0.0 via īœ˜ v18.14.0 via šŸ v3.10.9


No file/folder found for package myproject

Upvotes: 12

Views: 12927

Answers (4)

Weston A. Greene
Weston A. Greene

Reputation: 141

For me, I needed a file called myproject.py. (Could be an empty file.)

Otherwise running poetry install would throw:

Error: The current project could not be installed: No file/folder found for package myproject

Upvotes: 1

ravenwing
ravenwing

Reputation: 837

For those that will have same error as mine:

rename package-name to package_name

Upvotes: 3

Noumenon
Noumenon

Reputation: 6442

I got this error by running poetry install in the monorepo root (which had its own pyproject.toml, but wasn't meant to be installed) instead of the api folder with my real pyproject.toml.

Upvotes: 0

wongacj
wongacj

Reputation: 148

Short answer:

The directory where your pyproject.toml file sits needs to be share the same name, e.g., if the name config in pyproject.toml is name = "myproject", the directory needs to be also named myproject. Therefore, you must either:

  1. Rename the directory to match your name configuration in the pyproject.toml or
  2. Move the pyproject.toml file to the correct directory or
  3. If you don't care about making your project packageable by Poetry and only use poetry as your package manager for this project, add package-mode = false to your pyproject.toml.

Explanation:

There's a thread on the official GitHub for Poetry that discusses this issue. The gist of the issue is that whatever you choose for your project name, i.e., name = "myproject", needs to be the direct parent directory of where your pyproject.toml file lives. When there is a mismatch, you get the error you are getting.

Sources:

Upvotes: 11

Related Questions