Last updated: Apr 11, 2024
Reading time·2 min
virtualenvwrapper
If you use the native Python venv
command to create virtual environments or
the virtualenv
package, you can list the virtual environments by running a
find
command that looks for Python installations.
For example, if you are on Linux, you can use the following command.
# For Linux locate -b '\activate' | grep "/home"
If you are on macOS, you can use the following command.
# For macOS find $HOME -name "*activate" -type f
The following command works on both Linux and macOS.
# For macOS and Linux find ~ -d -name "site-packages" 2>/dev/null
The command looks for directories under $HOME
that are named site-packages
.
The venv
module places its pip-installed modules in a folder named
site-packages
.
On macOS and Linux, you can also use the following command which finds all symlinks to the Python binary.
# For macOS and Linux find ~ -type l -name python
If you are on macOS, you can also use the mdfind
command.
# For macOS mdfind -name activate | egrep /bin/activate$| xargs -o egrep -l nondestructive 2>/dev/null | xargs -L 1 dirname | xargs -L 1 dirname
If you need to list all virtual environments that were created using conda
,
use the conda info --envs
command.
conda info --envs
You can also use the conda env list
command.
conda env list
Both commands list all virtual environments created by conda
.
virtualenvwrapper
If you need to list all virtual environments that were created by the
virtualenvwrapper
module, use the lsvirtualenv
command.
lsvirtualenv -b
The -b
flag stands for brief mode and disables the verbose output.
If you want to run the command in long mode, use the -l
flag.
lsvirtualenv -l
Note that the command only lists the virtual environments that were created by
virtualenvwrapper
(with the mkvirtualenv
command).
The environment variables that were created using the mkvirtualenv
command are
usually all stored in ~/.virtualenvs
by default.
lsvirtualenv
, you have to have the virtualenvwrapper
module installed as shown in this section of the docs.You can also use the workon
command without passing it any arguments if you
use the virtualenvwrapper
module.
workon
The workon
command is used to list or change the working virtual environments.
If no environment name is given, the command prints the available virtual environments to stdout.
You can learn more about the related topics by checking out the following tutorials: