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.
Listing venv and virtualenv Environments (Manual Search)
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). The2>/dev/nullsuppresses 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/nullFinding 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 -dargument means "depth-first search".
Again, if you have a specific directory where you create environments, search within that directory instead.
Finding Python Executable Symlinks (Linux/macOS)
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:
Get-ChildItem -Path $HOME -Recurse -Include "Activate.ps1" -File -ErrorAction SilentlyContinue | Select-Object -ExpandProperty DirectoryName
where /R %HOMEPATH% python.exe- The
Get-ChildItemcommand finds theActivate.ps1files using recursion. - The
Select-Object -ExpandProperty DirectoryNameextracts 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
conda env listThese commands will output a list of all your conda environments, including the active environment (marked with an asterisk) and their locations:
base * /home/user/miniconda3
myenv /home/user/miniconda3/envs/myenv
anotherenv /home/user/miniconda3/envs/anotherenvListing 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)
workon # Also lists the virtual environmentslsvirtualenvandworkonare the standard commands used byvirtualenvwrapperfor listing all environments.