pypa/pip · error · VenvCreationError
Python executable failed to copy to {python_executable}
Error message
Python executable failed to copy to {python_executable} What it means
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.
Source
Thrown at src/pip/_internal/build_env/venv.py:101
# attributes, and only when they don't exist do we try to guess.
#
# These attributes seem to exist in every CPython version after 3.10.1 and
# are documented to exist on 3.12 and higher.
try:
self.python_executable = context.env_exec_cmd
except AttributeError:
try:
self.python_executable = context.env_exe
except AttributeError:
executable_name = "python.exe" if os.name == "nt" else "python"
self.python_executable = os.path.join(self._bin_path, executable_name)
self._save_env: dict[str, str | None] = {}
self._installer = installer
if not os.path.exists(self.python_executable):
# This error is only likely on Windows due to interference from AV software.
raise VenvCreationError(
f"Python executable failed to copy to {self.python_executable}"
)
def __enter__(self) -> None:
# We want backend calls to be able to use binaries installed as if this
# virtual environment was "activated".
self._save_env = {
name: os.environ.get(name, None) for name in ("PATH", "PYTHONPATH")
}
new_path = [self._bin_path]
if old_path := self._save_env["PATH"]:
new_path.extend(old_path.split(os.pathsep))
# However, we don't want a pre-existing PYTHONPATH to influence the
# backend calls.
os.environ.update({"PATH": os.pathsep.join(new_path), "PYTHONPATH": ""})
def __exit__(View on GitHub (pinned to f399c37189)
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.
Example fix
# before pip install --no-binary :all: <source-package> # after (rebuild deps pre-installed in current env) pip install -r build-reqs.txt pip install --no-build-isolation <source-package>
Defensive patterns
Strategy: try-catch
Validate before calling
# Pre-flight: ensure the base interpreter can create a venv with a usable python.
import subprocess, sys, tempfile, os
with tempfile.TemporaryDirectory() as d:
subprocess.check_call([sys.executable, "-m", "venv", d])
exe = os.path.join(d, "bin", "python") if os.name != "nt" else os.path.join(d, "Scripts", "python.exe")
assert os.path.exists(exe), "venv creation does not produce a python executable"
print("venv OK") Try / catch
# Wrap the install; retry once on VenvCreationError (common AV race), then surface a clear message.
from pip._internal.exceptions import VenvCreationError
import subprocess, sys
for attempt in range(2):
rc = subprocess.call([sys.executable, "-m", "pip", "install", PKG])
if rc == 0:
break
# VenvCreationError surfaces in pip's stderr; on known AV platforms, retry/advise.
else:
print("venv build failed; check antivirus/disk and retry, or use --no-build-isolation") Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- --build-constraint cannot be used with --no-build-isolation.
- To modify pip, please run the following command: {}
- non-local file URIs are not supported on this platform: {url
- path '%s' cannot be absolute
- path '%s' cannot end with '/'
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/7343f32e6162f613.
Report an issue: GitHub.