What this error means
The virtual environment was not created successfully because ensurepip is not available means Python is using an interpreter, package environment, certificate store, or virtual environment that does not match what the script expects.
Why this happens
Python commands can silently target different interpreters depending on PATH, shell activation, and virtual environment state.
For Python venv ensurepip is not available, verify the active Python executable before installing packages or changing source code.
Quick fixes
- Check the active interpreter with
python3 --version. - Use
python -m pipso pip targets the interpreter that runs the code. - Install the system venv package for your Python version, then recreate the virtual environment.
- Recreate the virtual environment if the interpreter version changed.
Copy-paste commands
Check Python version
python3 --version
Check pip target
python -m pip --version
List installed packages
python -m pip list
Create a virtual environment
python -m venv venv
Activate on macOS/Linux
source venv/bin/activate
Real-world fixes
- If imports fail after installation, the package was likely installed into a different interpreter.
- If SSL fails only in Python, update the CA bundle used by Python before disabling verification.
- Install the system venv package for your Python version, then recreate the virtual environment.
Step-by-step troubleshooting
- Confirm the failing traceback contains
The virtual environment was not created successfully because ensurepip is not available. - Run
python -m pip --versionand verify the path belongs to the expected environment. - Activate the virtual environment, then rerun the same version and pip checks.
- Install packages with
python -m pip install <package>rather than a barepipcommand. - Retry the smallest script or import that produced the error.
Platform-specific fixes
macOS
- If system Python and Homebrew Python both exist, use
python3 -m pipfrom the interpreter you run in production.
Linux
- On Debian/Ubuntu, install virtual environment support with
sudo apt install python3-venvwhenensurepipis missing.
Windows
- Use
py -m pip --versionandpy -m venv venvwhen the Python launcher is installed.
How to prevent it
- Use a virtual environment per project.
- Record dependencies in
requirements.txt,pyproject.toml, or the project lockfile. - Use
python -m pipin documentation and CI scripts.