Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fix Command Not Found Error on Virtualenv

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

If you've installed virtualenv but your terminal says command not found: virtualenv (or virtualenv: command not found), you're not alone. This usually happens because the executable isn't in your system's PATH, or the installation didn't complete properly. This guide walks you through the most common fixes, from checking your installation to adjusting your shell configuration.

What You'll Need

  • A terminal or command prompt (Terminal on macOS/Linux, Command Prompt or PowerShell on Windows)
  • Python installed (version 3.x recommended)
  • Pip (Python's package installer) – usually comes with Python
  • Basic familiarity with running commands

Step-by-Step

  1. Verify Python and pip are installed. Run python --version and pip --version. If you get errors, install Python first from python.org or your package manager.
  2. Check if virtualenv is actually installed. Run pip show virtualenv. If it shows package info, it's installed. If not, install it with pip install virtualenv (or pip3 install virtualenv on some systems).
  3. Find where virtualenv was installed. Run pip show -f virtualenv and look for the Location: field. The executable should be in the same directory as Python's bin (Linux/macOS) or Scripts (Windows) folder.
  4. Add that directory to your PATH.
    • Linux/macOS: Open your shell config file (~/.bashrc, ~/.zshrc, or ~/.profile) and add: export PATH="$PATH:/path/to/python/bin". Then run source ~/.bashrc (or the appropriate file).
    • Windows: Open System Properties → Environment Variables → Edit the Path variable → Add the Scripts folder (e.g., C:\Python39\Scripts). Click OK and restart your terminal.
  5. Use the module syntax if PATH isn't working. Instead of virtualenv, try python -m virtualenv. This works regardless of PATH issues and is often the simplest workaround.
  6. Reinstall virtualenv with the correct user scope. If you're on Linux/macOS and used sudo before, try installing without sudo: pip install --user virtualenv. This puts it in your user's bin directory, which is often already in PATH.
  7. Check for multiple Python versions. If you have both Python 2 and 3, pip might be installing for a different Python than the one you're using. Use python3 -m pip install virtualenv to be explicit.
  8. Restart your terminal. After any PATH change, close and reopen your terminal, or run exec $SHELL to reload your shell.

Common Mistakes

  • Using the wrong pip. On some systems, pip points to Python 2 while pip3 points to Python 3. Check with pip --version.
  • Not adding the correct directory to PATH. Make sure you're adding the directory that actually contains the virtualenv executable, not the parent directory.
  • Forgetting to reload the shell. PATH changes don't take effect until you restart the terminal or source your config file.
  • Using sudo unnecessarily. Installing with sudo pip can install to a system location that's not in your user's PATH, causing the command to not be found.
  • Not checking if virtualenv is already installed. Sometimes the error is a typo, like virtualenv vs virtualenv (extra 'v').

Tips

  • Prefer python -m virtualenv over the bare command. It's more reliable and avoids PATH issues entirely.
  • Consider using python -m venv instead. The built-in venv module is included with Python 3 and doesn't require a separate install. Just run python -m venv myenv.
  • Use a virtual environment manager. Tools like virtualenvwrapper or pipenv handle PATH and activation for you, but they add complexity.
  • Keep your Python environment clean. Avoid mixing system Python and Homebrew/Anaconda installations, as that can cause conflicting paths.
  • Check your shell's startup files. If you use a custom shell like fish or zsh, make sure you're editing the right config file.

Troubleshooting

If you still get 'command not found' after following the steps:

  • Run which virtualenv (Linux/macOS) or where virtualenv (Windows). If it returns nothing, the executable truly isn't in PATH. If it returns a path, try running that full path directly.
  • Check if the executable exists. Navigate to the directory pip reported (e.g., cd /usr/local/bin) and list files with ls | grep virtual. If it's there, the PATH is the issue.
  • Try reinstalling with --force-reinstall. Sometimes a corrupted installation causes the command to be missing. Run pip install --force-reinstall virtualenv.
  • Check for permission issues. If you see Permission denied when trying to run virtualenv, the file may not have execute permissions. Use chmod +x /path/to/virtualenv.
  • If using Windows, check the Scripts folder. Sometimes the Scripts folder is not in PATH even after adding it. Restart your computer to ensure the environment variable is picked up.
  • If you're using a version manager like pyenv or conda, the virtualenv executable might be inside that environment. Activate the environment first, or use the full path.

Frequently Asked Questions

Why does 'pip install virtualenv' succeed but the command still isn't found?

This usually means the installation directory (e.g., ~/.local/bin or C:\Python\Scripts) is not in your PATH. Check the pip output for the location and add it manually.

What's the difference between 'virtualenv' and 'venv'?

venv is a built-in module in Python 3 that provides similar functionality. virtualenv is a third-party package that works with older Python versions and offers more features. For new projects, python -m venv is recommended.

Can I use 'python -m virtualenv' instead of the command?

Yes, absolutely. It's actually the recommended way because it bypasses PATH issues. Just replace virtualenv myenv with python -m virtualenv myenv.

I'm on Windows and get 'virtualenv' is not recognized as an internal or external command. What now?

This is a PATH issue. Find the Scripts folder in your Python installation (e.g., C:\Users\YourName\AppData\Local\Programs\Python\Python39\Scripts) and add it to your system PATH via Environment Variables. Then restart your command prompt.

Do I need to install virtualenv if I'm using Python 3?

No, you can use the built-in venv module. Run python -m venv myenv to create a virtual environment. If you specifically want virtualenv for its extra features, then yes, install it.

How do I uninstall virtualenv if I want to start fresh?

Run pip uninstall virtualenv. If you used --user, also check ~/.local/bin and remove the executable manually if needed.