{"record":{"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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/vcs/versioncontrol.py#L633-L669","documentation":"Raised by VersionControl.run_command() when the OS raises NotADirectoryError while trying to execute the VCS binary (git, svn, hg, bzr). This means the PATH contains an entry that is a file rather than a directory, causing the executable lookup to fail in an unexpected way. It is wrapped as a BadCommand.","triggerScenarios":"Calling run_command() where the subprocess spawn raises NotADirectoryError — typically because a PATH component is a regular file (e.g. '/usr/bin/git' accidentally listed in PATH instead of '/usr/bin'). The exception is caught at line 650 and re-raised as BadCommand.","commonSituations":"A malformed PATH environment variable with a file path instead of directory paths. A PATH entry like '/usr/local/bin/git' (pointing at the binary) rather than '/usr/local/bin'. A broken virtualenv or shell profile that corrupted PATH. A Docker image with an incorrectly set PATH.","solutions":["Print your PATH and verify every entry is a directory: 'echo $PATH | tr ':' \"\\n\" | xargs -I{} test -d {} && echo OK || echo BAD: {}'","Fix the PATH in your shell profile / Dockerfile so it contains only directory paths","Ensure the VCS binary (e.g. git) is installed: 'which git' and 'git --version'","If the VCS tool is missing, install it (e.g. 'apt-get install git')"],"exampleFix":"// before\n# PATH contains '/usr/bin/git' (a file) instead of '/usr/bin'\nexport PATH=\"/usr/bin/git:/usr/local/bin:$PATH\"\npip install git+https://example.com/repo.git\n// after\nexport PATH=\"/usr/bin:/usr/local/bin:$PATH\"\npip install git+https://example.com/repo.git","handlingStrategy":"validation","validationCode":"import os, shutil\n\ndef vcs_command_is_available(name: str) -> bool:\n    if not shutil.which(name):\n        return False\n    # verify PATH entries are directories\n    for entry in os.environ.get('PATH', '').split(os.pathsep):\n        if entry and not os.path.isdir(entry):\n            return False  # a PATH entry is not a directory\n    return True\n\n# before a VCS-based install\nif not vcs_command_is_available('git'):\n    raise EnvironmentError('git not found or PATH is malformed')","typeGuard":"import os\n\ndef path_entries_are_directories() -> bool:\n    return all(os.path.isdir(e) for e in os.environ.get('PATH', '').split(os.pathsep) if e)","tryCatchPattern":"from pip._internal.exceptions import BadCommand\n\ntry:\n    vc.run_command(['version'])\nexcept BadCommand as e:\n    if 'invalid PATH' in str(e):\n        raise EnvironmentError(f'fix PATH to contain only directories: {e}')\n    if 'do you have' in str(e):\n        raise EnvironmentError(f'install the VCS tool: {e}')\n    raise","preventionTips":["Ensure every PATH entry is a directory, never a file path","Install the required VCS binary (git, svn, hg) and verify with 'which <name>'","Validate PATH in shell profiles and Dockerfiles","Use absolute directory paths in PATH, not binary paths"],"tags":["vcs","path","environment","git","subprocess"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}