workon, mkvirtualenv and lsvirtualenv say command not found
workon: command not foundShort answer
workon is not a program on your PATH. virtualenvwrapper defines it as a shell function when its script, virtualenvwrapper.sh, is sourced. So the error means the script was never sourced, was sourced from the wrong path, or failed because PATH or the Python interpreter was not set first. Fix the lines in your shell startup file.
Fix it fast
1Find out which cause you have
Find out whether the script exists and whether the current shell has loaded it.
type workon pip show -f virtualenvwrapper | grep -i "virtualenvwrapper.sh"2Match what you see, then jump to its fix
- 1
type workon prints nothing, but virtualenvwrapper.sh exists on diskThe source line is missing from the shell startup fileFix - 2
No such file or directory when the shell starts, naming virtualenvwrapper.shThe source line points at the wrong placeFix - 3
The source line is right but the script cannot find python or virtualenv at startupPATH or the Python interpreter is set after the script loadsFix
- 1
What does the error look like?
workon: command not foundmkvirtualenv: command not foundbash: workon: command not found after a fresh terminal
Cause 1 of 3
The source line is missing from the shell startup file
1Check
pip only installs the files. The commands appear when the startup file of your shell sources virtualenvwrapper.sh. Look for the line.
grep -n virtualenvwrapper ~/.bashrc ~/.profile2Fix
Add the variables and the source line to ~/.bashrc, then reload the file. The path after source must be where the script actually is.
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh3Verify
Reload the file and ask for the command again.
source ~/.bashrc
type workonConfirmed by virtualenvwrapper.readthedocs.io
Cause 2 of 3
The source line points at the wrong place
1Check
The install page shows /usr/local/bin/virtualenvwrapper.sh but says your path may differ. A pip install with --user puts the script in your user directory (usually ~/.local), not /usr/local.
command -v virtualenvwrapper.sh
ls ~/.local/bin/virtualenvwrapper.sh2Fix
Put the real path in the source line.
source ~/.local/bin/virtualenvwrapper.sh3Verify
Open a new terminal and run workon with no arguments; it lists your environments (empty if you have none).
workonConfirmed by virtualenvwrapper.readthedocs.io
Cause 3 of 3
PATH or the Python interpreter is set after the script loads
1Check
The script looks for python and virtualenv when it is sourced, so PATH must already be set. VIRTUALENVWRAPPER_PYTHON must be a full path and must also be set before the script is sourced.
grep -n -E "PATH|VIRTUALENVWRAPPER_PYTHON|virtualenvwrapper" ~/.bashrc
command -v python32Fix
Move the PATH and VIRTUALENVWRAPPER_PYTHON lines above the source line. Use the interpreter that has virtualenvwrapper installed.
export PATH="$HOME/.local/bin:$PATH"
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
source ~/.local/bin/virtualenvwrapper.sh3Verify
Open a new terminal and create a test environment.
mkvirtualenv test-envConfirmed by virtualenvwrapper.readthedocs.io
How do I stop it coming back?
- Install virtualenvwrapper into your base Python, not while a virtualenv is active.
- Keep the three lines (PATH, VIRTUALENVWRAPPER_PYTHON, source) together and in that order in one startup file.
- After moving to a new machine or a new Python, re-check the path in the source line.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
apt-get does not exist on this EC2 instance
sudo: apt-get: command not found
apt-get belongs to Debian and Ubuntu.
2 causes, each with a fixServers
bash warns that it cannot change the locale after you log in to a server
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
The shell was told to use a locale that is not built on the server.
3 causes, each with a fixServers
Syntax error: redirection unexpected when a Bash script runs under sh
script.sh: 12: Syntax error: redirection unexpected
The operators <<< (here-string) and &> are Bash features.
3 causes, each with a fixServers
ping is missing inside a Docker container
sh: 1: ping: not found
Base images such as ubuntu are minimal, so ping is simply not installed.
2 causes, each with a fixServers
Running ps inside a container says command not found
bash: ps: command not found
Slim Debian and Ubuntu images do not ship the procps package, and ps comes from procps.
2 causes, each with a fixServers
GitHub Actions step fails writing to GITHUB_OUTPUT
Error: Invalid format '...'
The runner reads GITHUB_OUTPUT line by line, and every entry must be name=value or a name<<DELIMITER block.
3 causes, each with a fix