Skip to main content

How to List All Virtual Environments in Python

Managing multiple Python projects often requires using virtual environments to isolate dependencies. Knowing how to list all available virtual environments is crucial for switching between projects, verifying setups, and general organization.

This guide covers how to list environments created with the standard venv, the popular virtualenv package, conda, and virtualenvwrapper.

Since venv (the built-in virtual environment module) and virtualenv (a popular third-party package) don't have built-in commands to list all environments, you generally need to search your filesystem for them. The standard practice is to create virtual environments within your project directories, or in a dedicated directory (like ~/.virtualenvs). The key is to look for common files/directories created by these tools.

Finding activate Scripts (Linux/macOS)

Virtual environments created with venv and virtualenv contain an activate script (used to activate the environment). You can use find (or locate, if available and up-to-date) to find these scripts:

find ~/ -name "activate" -type f 2>/dev/null
  • This will find any file with name "activate" that are actually files, not directories, and will also discard all errors using /dev/null
  • This command recursively searches your home directory (~) for files named "activate" that are regular files (-type f). The 2>/dev/null suppresses error messages (like "Permission denied").

If you know your virtual environments are in a specific directory (e.g., ~/Envs or ~/my_projects), search within that directory instead of your entire home directory for efficiency. For example:

find ~/Envs -name "activate" -type f 2>/dev/null
find ~/my_projects -name "activate" -type f 2>/dev/null
note

You may want to search other paths, but make sure not to use paths like / which might lead to the script getting stuck.

Finding site-packages Directories (Linux/macOS)

Another approach is to search for the site-packages directory, which contains the installed packages for a virtual environment:

find ~ -d -name "site-packages" 2>/dev/null
  • This command searches the home directory, and returns the directories whose name is site-packages
  • -d argument means "depth-first search".

Again, if you have a specific directory where you create environments, search within that directory instead.

A final option for Linux and macOS is to find symbolic links named python within your virtual environments:

find ~ -type l -name python 2>/dev/null
  • This will look for symlinks named python in the home directory.

Finding activate Scripts (Windows)

On Windows, the activate script is usually named activate.bat or Activate.ps1 (for PowerShell), and they're located in the Scripts directory of your environment. You can use the where command to locate python executables:

# Using PowerShell (recommended)
Get-ChildItem -Path $HOME -Recurse -Include "Activate.ps1" -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty DirectoryName

#Using where command
where /R %HOMEPATH% python.exe
  • The Get-ChildItem command finds the Activate.ps1 files using recursion.
  • The Select-Object -ExpandProperty DirectoryName extracts the full directory path to the file, so that the locations where the virtual environments are set up will be returned.

Listing Conda Environments

Conda has built-in commands to list environments:

conda info --envs
# or, equivalently:
conda env list

These commands will output a list of all your conda environments, including the active environment (marked with an asterisk) and their locations:

# conda environments:
#
base * /home/user/miniconda3
myenv /home/user/miniconda3/envs/myenv
anotherenv /home/user/miniconda3/envs/anotherenv
note

Conda stores all of its virtual environments in the same folder, usually located in the root install directory of miniconda or anaconda.

Listing virtualenvwrapper Environments

If you use virtualenvwrapper, the lsvirtualenv command lists your environments:

lsvirtualenv -b  # Brief output (just the names)
lsvirtualenv -l # Long output (more details, if available)
# or
workon # Also lists the virtual environments
  • lsvirtualenv and workon are the standard commands used by virtualenvwrapper for listing all environments.