{"record":{"id":"7343f32e6162f613","repo":"pypa/pip","slug":"python-executable-failed-to-copy-to-python-execut","errorCode":null,"errorMessage":"Python executable failed to copy to {python_executable}","messagePattern":"Python executable failed to copy to (.+?)","errorType":"exception","errorClass":"VenvCreationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/build_env/venv.py","lineNumber":101,"sourceCode":"        # attributes, and only when they don't exist do we try to guess.\n        #\n        # These attributes seem to exist in every CPython version after 3.10.1 and\n        # are documented to exist on 3.12 and higher.\n        try:\n            self.python_executable = context.env_exec_cmd\n        except AttributeError:\n            try:\n                self.python_executable = context.env_exe\n            except AttributeError:\n                executable_name = \"python.exe\" if os.name == \"nt\" else \"python\"\n                self.python_executable = os.path.join(self._bin_path, executable_name)\n\n        self._save_env: dict[str, str | None] = {}\n        self._installer = installer\n\n        if not os.path.exists(self.python_executable):\n            # This error is only likely on Windows due to interference from AV software.\n            raise VenvCreationError(\n                f\"Python executable failed to copy to {self.python_executable}\"\n            )\n\n    def __enter__(self) -> None:\n        # We want backend calls to be able to use binaries installed as if this\n        # virtual environment was \"activated\".\n        self._save_env = {\n            name: os.environ.get(name, None) for name in (\"PATH\", \"PYTHONPATH\")\n        }\n\n        new_path = [self._bin_path]\n        if old_path := self._save_env[\"PATH\"]:\n            new_path.extend(old_path.split(os.pathsep))\n        # However, we don't want a pre-existing PYTHONPATH to influence the\n        # backend calls.\n        os.environ.update({\"PATH\": os.pathsep.join(new_path), \"PYTHONPATH\": \"\"})\n\n    def __exit__(","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/build_env/venv.py#L83-L119","documentation":"Raised as VenvCreationError from VenvBuildEnvironment.__init__ (venv.py:101) after the build-isolation virtual environment is created. Once venv.EnvBuilder finishes, pip constructs the expected python executable path from the venv context (lines 87-94) and then asserts it exists at line 99. If the file is missing, the environment cannot be used to run PEP 517 build backends. The inline comment at line 100 notes this is most commonly caused by antivirus software on Windows interfering with the freshly written executable.","triggerScenarios":"Installing a package that requires building from source (no compatible wheel) while build isolation is enabled (the default), on a system where the venv's python binary is removed/quarantined between creation and the existence check.","commonSituations":"Windows hosts with aggressive real-time antivirus (Defender, third-party AV) that quarantine or delete the copied/symlinked python.exe; broken or partial Python installs where venv creation silently fails to place the binary; filesystem permissions, full disk, or network-mounted home dirs that drop the executable.","solutions":["Add the pip cache and temp directories (and the Python install) to your antivirus exclusions, then retry the install.","Retry the install: transient AV races often succeed on a second attempt.","Disable build isolation with `--no-build-isolation` and pre-install the build requirements in the current environment (only if you can supply the build deps yourself).","Reinstall or repair the base Python interpreter so venv creation reliably produces a working executable."],"exampleFix":"# before\npip install --no-binary :all: <source-package>\n# after (rebuild deps pre-installed in current env)\npip install -r build-reqs.txt\npip install --no-build-isolation <source-package>","handlingStrategy":"try-catch","validationCode":"# Pre-flight: ensure the base interpreter can create a venv with a usable python.\nimport subprocess, sys, tempfile, os\nwith tempfile.TemporaryDirectory() as d:\n    subprocess.check_call([sys.executable, \"-m\", \"venv\", d])\n    exe = os.path.join(d, \"bin\", \"python\") if os.name != \"nt\" else os.path.join(d, \"Scripts\", \"python.exe\")\n    assert os.path.exists(exe), \"venv creation does not produce a python executable\"\nprint(\"venv OK\")","typeGuard":null,"tryCatchPattern":"# Wrap the install; retry once on VenvCreationError (common AV race), then surface a clear message.\nfrom pip._internal.exceptions import VenvCreationError\nimport subprocess, sys\nfor attempt in range(2):\n    rc = subprocess.call([sys.executable, \"-m\", \"pip\", \"install\", PKG])\n    if rc == 0:\n        break\n    # VenvCreationError surfaces in pip's stderr; on known AV platforms, retry/advise.\nelse:\n    print(\"venv build failed; check antivirus/disk and retry, or use --no-build-isolation\")","preventionTips":["On Windows, exclude the pip cache and temp directories from real-time antivirus scanning.","Keep build dependencies pre-installed so you can fall back to --no-build-isolation if needed."],"tags":["venv","build-isolation","windows","antivirus","venv-creation"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}