python-poetry/poetry · warning · ValueError
<warning>Environment "{python}" does not exist.</warning>
Error message
<warning>Environment "{python}" does not exist.</warning> What it means
Raised as ValueError in EnvManager.remove when the given name passes the project-ownership check (it starts with base_env_name) but none of the venvs returned by self.list() has a matching path.name. I.e., the env name looks like it belongs to this project but no such virtualenv is registered.
Source
Thrown at src/poetry/utils/env/env_manager.py:308
):
raise IncorrectEnvError(env_name)
except CalledProcessError as e:
raise EnvCommandError(e)
if self.check_env_is_for_current_project(python, self.base_env_name):
venvs = self.list()
for venv in venvs:
if venv.path.name == python:
# Exact virtualenv name
if self.envs_file.exists():
venv_minor = ".".join(str(v) for v in venv.version_info[:2])
self.envs_file.remove_section(self.base_env_name, venv_minor)
self.remove_venv(venv.path)
return venv
raise ValueError(
f'<warning>Environment "{python}" does not exist.</warning>'
)
else:
venv_path = self._poetry.config.virtualenvs_path
# Get all the poetry envs, even for other projects
env_names = [p.name for p in sorted(venv_path.glob("*-*-py*"))]
if python in env_names:
raise IncorrectEnvError(python)
try:
python_version = Version.parse(python)
python = f"python{python_version.major}"
if python_version.precision > 1:
python += f".{python_version.minor}"
except ValueError:
# Executable in PATH or full executable path
pass
View on GitHub (pinned to 92b74dcfe3)
Solutions
- List actual envs for this project: 'poetry env list' and remove one that appears there.
- If the env dir was deleted by hand, the message is effectively a no-op - nothing to remove; ignore it.
- Check that virtualenvs_path in config still points where the env was created.
- Recreate the env with 'poetry install' if you still need it.
Example fix
// before
manager.remove("myproject-py3.99") # never created -> ValueError
// after - remove an env that actually exists
manager.remove("myproject-py3.11") Defensive patterns
Strategy: validation
Validate before calling
def env_exists_for_project(manager, name: str) -> bool:
if not manager.check_env_is_for_current_project(name, manager.base_env_name):
return False
return any(venv.path.name == name for venv in manager.list()) Type guard
def is_missing_env_value_error(e: Exception) -> bool:
return isinstance(e, ValueError) and 'does not exist' in str(e) Try / catch
try:
manager.remove(name)
except ValueError as e:
if 'does not exist' in str(e):
# already gone - nothing to do
pass
else:
raise Prevention
- Call 'poetry env list' to confirm the env name exists for this project before removing.
- Treat 'does not exist' as effectively a no-op when the dir was already deleted by hand.
- Avoid manual rm -rf of venv dirs to keep Poetry's view consistent.
- Remember the warning tag - this is informational, not a hard failure.
When it happens
Trigger: Calling 'poetry env remove <name>' where <name> matches the project prefix but the concrete venv was already deleted, never created, or lives outside the discovered virtualenvs_path. Exact branch: env_manager.py:295-310.
Common situations: The venv directory was deleted by hand (rm -rf) but the user still references it; the virtualenvs_path changed between invocations; a typo in the env name that still happens to share the prefix; running after a cache cleanup tool removed envs.
Related errors
- <warning>Environment "{name}" does not exist.</warning>
- Env {env_name} doesn't belong to this project.
- Discovered shell '{shell}' doesn't have an activator in virt
- embedded {distribution} wheel not found
- Command {e.cmd} errored with the following return code {e.re
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/ae6beb83da876954.json.
Report an issue: GitHub.