python-poetry/poetry · error · RuntimeError
Destination <fg=yellow>{path}</> exists and is not empty. Di
Error message
Destination <fg=yellow>{path}</> exists and is not empty. Did you mean `poetry init`? What it means
RuntimeError from `poetry new` (new.py:75-79) when the destination path both exists and contains at least one entry (`list(path.glob('*'))` is non-empty). `new` scaffolds a fresh project; for existing directories use `poetry init`.
Source
Thrown at src/poetry/console/commands/new.py:77
def handle(self) -> int:
from pathlib import Path
if self.io.input.option("project"):
self.line_error(
"<warning>--project only makes sense with existing projects, and will"
" be ignored. You should consider the option --path instead.</warning>"
)
path = Path(self.argument("path"))
if not path.is_absolute():
# we do not use resolve here due to compatibility issues
# for path.resolve(strict=False)
path = Path.cwd().joinpath(path)
if path.exists() and list(path.glob("*")):
# Directory is not empty. Aborting.
raise RuntimeError(
f"Destination <fg=yellow>{path}</> exists and is not empty. Did you mean `poetry init`?"
)
if self.option("src"):
self.line_error(
"The <c1>--src</> option is now the default and will be removed in a future version."
)
return self._init_pyproject(
project_path=path,
allow_interactive=self.option("interactive"),
layout_name="standard" if self.option("flat") else "src",
readme_format=self.option("readme") or "md",
allow_layout_creation_on_empty=True,
)
View on GitHub (pinned to 92b74dcfe3)
Solutions
- Use `poetry init` in the existing directory to adopt it.
- Pick a fresh path: `poetry new mypkg-v2`.
- Empty or remove the existing directory if you truly want a clean scaffold.
Example fix
# before poetry new existing-dir # after cd existing-dir && poetry init
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
p = Path("mypkg")
if p.exists() and any(p.iterdir()):
raise SystemExit(f"{p} is non-empty; use `poetry init` instead") Type guard
def is_empty_or_missing(path: str) -> bool:
from pathlib import Path
p = Path(path)
return not p.exists() or not any(p.iterdir()) Prevention
- Prefer `poetry init` for existing directories.
- Check the target path before scripting `poetry new`.
- Keep scaffolding tooling idempotent by choosing unique names.
When it happens
Trigger: Running `poetry new mypkg` where `mypkg/` already exists with files; running inside a repo directory that is non-empty.
Common situations: Re-scaffolding over an existing project; choosing a name that collides with a sibling directory; misunderstanding `new` vs `init`.
Related errors
- Invalid layout
- {path} is not relative to any discovered {site_type}sites
- Unable to find a suitable destination for "{path}" in {paths
- Unable to access any of {paths_csv(candidates)}
- Specified path '{path}' is not a valid {'directory' if is_di
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/bf68dadd6ec1573c.json.
Report an issue: GitHub.