{"id":"af5c0b8f9689a3a5","repo":"pypa/pip","slug":"cannot-find-command-cls-name-r-invalid-path","errorCode":null,"errorMessage":"Cannot find command {cls.name!r} - invalid PATH","messagePattern":"Cannot find command (.+?) - invalid PATH","errorType":"exception","errorClass":"BadCommand","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/vcs/versioncontrol.py","lineNumber":651,"sourceCode":"        cmd = make_command(cls.name, *cmd)\n        if command_desc is None:\n            command_desc = format_command_args(cmd)\n        try:\n            return call_subprocess(\n                cmd,\n                show_stdout,\n                cwd,\n                on_returncode=on_returncode,\n                extra_ok_returncodes=extra_ok_returncodes,\n                command_desc=command_desc,\n                extra_environ=extra_environ,\n                unset_environ=cls.unset_environ,\n                spinner=spinner,\n                log_failed_cmd=log_failed_cmd,\n                stdout_only=stdout_only,\n            )\n        except NotADirectoryError:\n            raise BadCommand(f\"Cannot find command {cls.name!r} - invalid PATH\")\n        except FileNotFoundError:\n            # errno.ENOENT = no such file or directory\n            # In other words, the VCS executable isn't available\n            raise BadCommand(\n                f\"Cannot find command {cls.name!r} - do you have \"\n                f\"{cls.name!r} installed and in your PATH?\"\n            )\n        except PermissionError:\n            # errno.EACCES = Permission denied\n            # This error occurs, for instance, when the command is installed\n            # only for another user. So, the current user don't have\n            # permission to call the other user command.\n            raise BadCommand(\n                f\"No permission to execute {cls.name!r} - install it \"\n                f\"locally, globally (ask admin), or check your PATH. \"\n                f\"See possible solutions at \"\n                f\"https://pip.pypa.io/en/latest/reference/pip_freeze/\"\n                f\"#fixing-permission-denied.\"","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/vcs/versioncontrol.py#L633-L669","documentation":"Raised by `VCS.run_command` when invoking the VCS executable raises `NotADirectoryError`. This means an entry in the `PATH` environment variable resolves to something that is not a directory, so the OS cannot traverse it to find the executable. pip wraps it as a `BadCommand` so the failure surfaces as a configuration problem with PATH rather than an unhandled OS exception.","triggerScenarios":"Any pip VCS operation calls `run_command([cls.name, ...])` (git/svn/hg/bzr) and `call_subprocess` raises `NotADirectoryError` because a PATH component is a file, a broken symlink, or a stale mountpoint.","commonSituations":"A corrupted/mis-set `PATH` (e.g. `PATH=/usr/bin/git:/bin` where a component is a file not a dir); a stale NFS/FUSE mount that previously held the bin directory; a virtualenv whose `bin` was replaced by a symlink to a file; shell rc files appending non-directory entries.","solutions":["Inspect `echo $PATH` and remove any entry that is not an existing directory (`for d in ${PATH//:/ }; do [ -d \"$d\" ] || echo \"bad: $d\"; done`).","Re-activate your virtualenv or fix the activation script so PATH points to real directories.","Restore PATH to the system default and re-add only valid bin directories."],"exampleFix":"# before\nexport PATH=/usr/local/bin/git:/usr/bin:/bin   # /usr/local/bin/git is a file\n\n# after\nexport PATH=/usr/local/bin:/usr/bin:/bin","handlingStrategy":"validation","validationCode":"import os\n\ndef validate_path_dirs() -> list[str]:\n    bad = [d for d in os.environ.get(\"PATH\", \"\").split(os.pathsep) if d and not os.path.isdir(d)]\n    if bad:\n        raise EnvironmentError(f\"PATH contains non-directory entries: {bad}\")\n    return bad","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Sanitize PATH at shell startup to only existing directories.","Re-activate virtualenvs rather than hand-editing PATH.","In Docker images, set PATH only to directories you `mkdir`'d."],"tags":["vcs","path","environment","configuration"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}