{"id":"df55057ca1f66728","repo":"python-poetry/poetry","slug":"command-e-cmd-errored-with-the-following-return-df5505","errorCode":null,"errorMessage":"Command {e.cmd} errored with the following return code {e.returncode}","messagePattern":"Command (.+?) errored with the following return code (.+?)","errorType":"exception","errorClass":"EnvCommandError","httpStatus":null,"severity":"error","filePath":"src/poetry/utils/env/env_manager.py","lineNumber":293,"sourceCode":"        This is done to prevent action on other project's envs.\n        \"\"\"\n        return env.startswith(base_env_name)\n\n    def remove(self, python: str) -> Env:\n        python_path = Path(python)\n        if python_path.is_file():\n            # Validate env name if provided env is a full path to python\n            try:\n                env_dir = subprocess.check_output(\n                    [python, \"-c\", GET_ENV_PATH_ONELINER], text=True, encoding=\"locale\"\n                ).strip(\"\\n\")\n                env_name = Path(env_dir).name\n                if not self.check_env_is_for_current_project(\n                    env_name, self.base_env_name\n                ):\n                    raise IncorrectEnvError(env_name)\n            except CalledProcessError as e:\n                raise EnvCommandError(e)\n\n        if self.check_env_is_for_current_project(python, self.base_env_name):\n            venvs = self.list()\n            for venv in venvs:\n                if venv.path.name == python:\n                    # Exact virtualenv name\n                    if self.envs_file.exists():\n                        venv_minor = \".\".join(str(v) for v in venv.version_info[:2])\n                        self.envs_file.remove_section(self.base_env_name, venv_minor)\n\n                    self.remove_venv(venv.path)\n\n                    return venv\n\n            raise ValueError(\n                f'<warning>Environment \"{python}\" does not exist.</warning>'\n            )\n        else:","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/utils/env/env_manager.py#L275-L311","documentation":"Raised as EnvCommandError in EnvManager.remove when subprocess.check_output([python, '-c', GET_ENV_PATH_ONELINER]) fails with CalledProcessError. This happens for the code path at env_manager.py:283-293 where the argument is an existing file that Poetry assumed was a python executable, but invoking it to discover its env directory errored.","triggerScenarios":"Calling 'poetry env remove <path>' where <path>.is_file() is True but the file is not a runnable python interpreter (not executable, wrong arch, missing shared libs, or it exits non-zero when probed for sys.prefix).","commonSituations":"Pointing env remove at a python binary whose dependencies are missing (libpython .so removed), a stale symlink to a deleted interpreter, a file that merely happens to be named 'python', or a binary for the wrong platform.","solutions":["Run the failing probe yourself: '<path> -c \"import sys; print(sys.prefix)\"' and read the real error.","If the interpreter is broken, remove the leftover venv directory manually and reinstall the interpreter.","Point env remove at the env NAME (from 'poetry env list') instead of the raw python path.","Ensure the file is executable (chmod +x) and its shared libraries resolve (ldd <path>)."],"exampleFix":"// before\nmanager.remove(\"/opt/broken-python/bin/python\")  # EnvCommandError\n\n// after - fix or remove the broken interpreter, then remove by name\nmanager.remove(\"myproject-py3.11\")","handlingStrategy":"validation","validationCode":"import subprocess\nfrom pathlib import Path\n\ndef interpreter_is_runnable(path: str) -> bool:\n    p = Path(path)\n    if not p.is_file():\n        return False\n    try:\n        subprocess.check_output([path, \"-c\", \"import sys; print(sys.prefix)\"], text=True)\n        return True\n    except (subprocess.CalledProcessError, OSError):\n        return False","typeGuard":"from poetry.utils.env.exceptions import EnvCommandError, EnvError\n\ndef is_env_command_error(e: Exception) -> bool:\n    return isinstance(e, EnvCommandError) or isinstance(e, EnvError)","tryCatchPattern":"from poetry.utils.env.exceptions import EnvCommandError\n\ntry:\n    manager.remove(python_path)\nexcept EnvCommandError as e:\n    # probe failed - try removing by env name instead\n    name = pick_env_name_from(manager.list())\n    manager.remove(name)","preventionTips":["Verify the interpreter runs (path -c 'print(1)') before passing it to env remove.","Prefer removing by env name from 'poetry env list' over raw interpreter paths.","Check the binary is executable and its shared libs resolve (ldd / otool -L).","Remove orphaned venv directories directly if the interpreter is unrecoverable."],"tags":["env-remove","subprocess","interpreter","broken-binary"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}