Virtualenv
Command Not Found
Python
Environment Setup
Troubleshooting

Virtualenv Command Not Found

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The virtualenv: command not found error means the virtualenv package is either not installed or installed in a location that is not on your system's PATH. The fix depends on your setup: install it with pip install virtualenv, use python -m virtualenv to bypass PATH issues, or switch to the built-in python -m venv module that requires no separate installation (Python 3.3+).

The Error

bash
1virtualenv myenv
2# bash: virtualenv: command not found
3
4# Or on some systems:
5# zsh: command not found: virtualenv

Fix 1: Install virtualenv

bash
1# Install globally
2pip install virtualenv
3
4# Or with pip3 explicitly
5pip3 install virtualenv
6
7# Or with the --user flag (no sudo needed)
8pip install --user virtualenv
9
10# Verify installation
11virtualenv --version

Fix 2: Use python -m virtualenv

If virtualenv is installed but not on PATH, invoke it through Python:

bash
1python -m virtualenv myenv
2
3# Or with explicit Python version
4python3 -m virtualenv myenv
5python3.11 -m virtualenv myenv

This works because python -m looks in Python's package directories, not the system PATH.

Python 3.3+ includes the venv module — no installation needed:

bash
1python3 -m venv myenv
2
3# Activate it
4source myenv/bin/activate    # macOS/Linux
5myenv\Scripts\activate       # Windows
6
7# Deactivate
8deactivate

venv is the officially recommended tool for creating virtual environments in modern Python. It is lighter than virtualenv and ships with Python.

Fix 4: PATH Issues After pip install --user

When installed with --user, pip places executables in a user-local directory that may not be on PATH:

bash
1# Find where pip installed it
2python3 -m site --user-base
3# Output: /Users/yourname/.local (macOS/Linux)
4# The binary is at: /Users/yourname/.local/bin/virtualenv
5
6# Add to PATH in ~/.bashrc or ~/.zshrc
7export PATH="$HOME/.local/bin:$PATH"
8
9# Reload shell
10source ~/.bashrc  # or source ~/.zshrc
11
12# Now it works
13virtualenv --version

On macOS with Homebrew Python:

bash
# Homebrew Python user bin
export PATH="$HOME/Library/Python/3.11/bin:$PATH"

Fix 5: Multiple Python Versions

When multiple Python versions are installed, pip and pip3 may point to different versions:

bash
1# Check which Python pip is using
2pip --version
3# pip 23.3.1 from /usr/lib/python3.11/site-packages (python 3.11)
4
5pip3 --version
6# pip 23.3.1 from /usr/local/lib/python3.12/site-packages (python 3.12)
7
8# Install for a specific Python version
9python3.11 -m pip install virtualenv
10python3.11 -m virtualenv myenv

Fix 6: System Package Manager

On some Linux distributions, install via the system package manager:

bash
1# Ubuntu/Debian
2sudo apt install python3-virtualenv
3
4# Fedora
5sudo dnf install python3-virtualenv
6
7# Arch Linux
8sudo pacman -S python-virtualenv
9
10# macOS with Homebrew
11brew install virtualenv

System packages avoid pip permission issues but may install older versions.

Fix 7: Windows-Specific

powershell
1# Install
2pip install virtualenv
3
4# If pip is not on PATH, use the full path
5py -m pip install virtualenv
6
7# Create environment
8py -m virtualenv myenv
9
10# Or use built-in venv
11py -m venv myenv
12
13# Activate
14myenv\Scripts\activate
15
16# If execution policy blocks activation
17Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
18myenv\Scripts\activate

virtualenv vs venv

Featurevenvvirtualenv
InstallationBuilt into Python 3.3+Requires pip install
SpeedSlowerFaster (caches packages)
Python 2 supportNoYes
Multiple Python versionsCurrent version onlyCan target any installed version
--system-site-packagesYesYes
Recommended forMost projectsLegacy Python 2 or specific needs
bash
1# venv creates environment with current Python
2python3 -m venv myenv
3
4# virtualenv can target a specific Python
5virtualenv --python=python3.9 myenv

Verifying the Environment Works

bash
1# Create and activate
2python3 -m venv myenv
3source myenv/bin/activate
4
5# Verify
6which python     # /path/to/myenv/bin/python
7which pip        # /path/to/myenv/bin/pip
8python --version # Python 3.x.x
9
10# Install packages (isolated to this environment)
11pip install requests
12
13# Deactivate
14deactivate
15
16# Verify we're back to system Python
17which python     # /usr/bin/python3 or similar

Common Pitfalls

  • Using sudo pip install: This installs packages globally and can break system Python. Use pip install --user virtualenv or a virtual environment manager like pipx instead.
  • Forgetting to activate: After creating a virtual environment, you must source myenv/bin/activate before using it. Running pip install without activating installs packages globally.
  • .local/bin not on PATH: pip install --user puts binaries in ~/.local/bin which many shells do not include by default. Add it to your shell profile.
  • Confusing virtualenv with venv: They do the same thing. venv is built-in and simpler. virtualenv is a third-party package with more features. For most projects, venv is sufficient.
  • Python version mismatch: pip install virtualenv installs for whichever Python pip is linked to. If you have Python 3.9 and 3.11, pip3.11 install virtualenv ensures it is installed for 3.11.

Summary

  • command not found means virtualenv is not installed or not on PATH
  • Install with pip install virtualenv or use python -m virtualenv
  • Use python3 -m venv myenv instead — it is built-in and requires no installation
  • Add ~/.local/bin to PATH if using pip install --user
  • On Linux, the system package manager (apt, dnf) avoids pip permission issues
  • venv is recommended for most projects; virtualenv for Python 2 or multi-version needs

Course illustration
Course illustration

All Rights Reserved.