{"record":{"id":"9fb4d734bd5c1b8b","repo":"pypa/pip","slug":"target-path-exists-but-is-not-a-directory-will-no","errorCode":null,"errorMessage":"Target path exists but is not a directory, will not continue.","messagePattern":"Target path exists but is not a directory, will not continue\\.","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/commands/install.py","lineNumber":422,"sourceCode":"            options.use_user_site,\n            prefix_path=options.prefix_path,\n            target_dir=options.target_dir,\n            root_path=options.root_path,\n            isolated_mode=options.isolated_mode,\n        )\n\n        target_temp_dir: TempDirectory | None = None\n        target_temp_dir_path: str | None = None\n        if options.target_dir:\n            options.ignore_installed = True\n            options.target_dir = os.path.abspath(options.target_dir)\n            if (\n                # fmt: off\n                os.path.exists(options.target_dir) and\n                not os.path.isdir(options.target_dir)\n                # fmt: on\n            ):\n                raise CommandError(\n                    \"Target path exists but is not a directory, will not continue.\"\n                )\n\n            # Create a target directory for using with the target option\n            target_temp_dir = TempDirectory(kind=\"target\")\n            target_temp_dir_path = target_temp_dir.path\n            self.enter_context(target_temp_dir)\n\n        session = self.get_default_session(options)\n\n        target_python = make_target_python(options)\n        finder = self._build_package_finder(\n            options=options,\n            session=session,\n            target_python=target_python,\n            ignore_requires_python=options.ignore_requires_python,\n        )\n        build_tracker = self.enter_context(get_build_tracker())","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/commands/install.py#L404-L440","documentation":"Raised by `pip install --target <path>` when the path exists but is a regular file (not a directory). InstallCommand.run at install.py:416 checks `os.path.exists(target_dir) and not os.path.isdir(target_dir)`; a file at that location makes installation impossible and is rejected before any work begins.","triggerScenarios":"Passing --target a path that already exists as a file (e.g. `--target requirements.txt` or a path where a file was accidentally created).","commonSituations":"Reusing a filename as a target dir, a typo pointing --target at an existing file, or a prior misdirected command created a file where a directory was expected.","solutions":["Choose a target path that is either a directory or does not exist: `--target ./libs`.","If a file is wrongly there, remove or rename it first: `rm <file>` then retry.","Verify with `ls -ld <path>` that the target is a directory before running."],"exampleFix":"// before\npip install --target libs.zip numpy   # libs.zip is a file\n// after\nrm libs.zip\npip install --target ./libs numpy","handlingStrategy":"validation","validationCode":"# Verify --target is absent or a directory before pip install\nimport os\n\ndef target_dir_ok(path):\n    if path is None:\n        return True\n    if os.path.exists(path) and not os.path.isdir(path):\n        raise ValueError(\"--target %s exists and is not a directory\" % path)\n    return True\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose a --target path that is a directory or does not yet exist.","Run `ls -ld <path>` to confirm the target type before installing."],"tags":["cli","pip-install","filesystem","path-validation","usage-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}