HOWTO · Python
How to List Virtual Environments in Python
List Python environments with virtualenvwrapper or Conda, understand workon, and troubleshoot missing environments with WORKON_HOME.
On this page
Use lsvirtualenv or workon without arguments for environments managed by virtualenvwrapper. Use conda env list for Conda environments. You do not need to activate an environment to list it, but the relevant manager must be available in your terminal.
List virtual environments in Python
Python has no universal command that lists every environment on your computer. The correct method depends on how you created and organized them:
| Environment tool | Listing method | Scope |
|---|---|---|
| virtualenvwrapper | lsvirtualenv or workon |
Environments in the configured WORKON_HOME directory |
| Conda | conda env list |
Environments known to the current Conda installation |
Plain venv or virtualenv |
Inspect the directories where you created them | No shared registry of all environments |
A virtual environment gives a project its own Python environment and installed packages. For example, Project1 and Project2 can use different NumPy versions without repeatedly changing one shared installation. This reduces dependency conflicts, but incompatible packages can still be installed within an environment.
For plain venv environments, look in your project directories for folders such as .venv. A pyvenv.cfg file is a useful marker, although its presence alone does not prove that an environment still works.
This self-contained Python example creates two temporary environments, lists their names, and cleans up afterward. It searches only the temporary parent directory and prints project1 and project2 on separate lines.
from pathlib import Path
from tempfile import TemporaryDirectory
import venv
with TemporaryDirectory() as directory:
root = Path(directory)
for name in ("project1", "project2"):
venv.EnvBuilder(with_pip=False).create(root / name)
for folder in sorted(root.iterdir()):
if folder.is_dir() and (folder / "pyvenv.cfg").is_file():
print(folder.name)
project1
project2
To inspect your own environments, use their known parent directory instead of creating temporary ones. This marker-based approach is for venv-style directories; use Conda’s own listing command for Conda environments.
List environments with virtualenvwrapper
The lsvirtualenv command belongs to virtualenvwrapper, a collection of shell tools for organizing environments created with virtualenv. Installing virtualenv alone does not provide these wrapper commands.
For a Bash setup on Linux or macOS, follow the official virtualenvwrapper installation and shell initialization guide. The basic sequence is:
- If needed, install the tools with
python3 -m pip install virtualenv virtualenvwrapperusing a Python installation that permits pip installations. - Choose a shared parent directory, for example with
export WORKON_HOME="$HOME/.virtualenvs", then create it withmkdir -p "$WORKON_HOME". - Locate the installed
virtualenvwrapper.shscript and load it into your current shell withsource /actual/path/to/virtualenvwrapper.sh, replacing the path with its installed location. - Run
lsvirtualenv, orlsvirtualenv -bfor a brief list of names. Listing existing environments does not require creating another one. To create a managed environment when needed, usemkvirtualenv vEnv1.
The official command reference describes lsvirtualenv and its listing options, and workon for listing or activating environments.
These setup commands are unexecuted instructions requiring the installed tools and a compatible shell. Installation alone does not initialize your current shell. Add the directory setting and script-loading command to the appropriate shell startup file if you want them available in future sessions. Native Windows ports have different setup instructions; do not assume this Bash sequence applies to Command Prompt or PowerShell.
If the command is unavailable, check installation and shell initialization. If it runs but lists no environments, inspect WORKON_HOME: in Bash, use printf '%s\n' "$WORKON_HOME" and then ls -la "$WORKON_HOME" to examine the configured directory.
Set WORKON_HOME to the parent containing your environment folders, rather than to an individual environment’s folder. Defaults vary by platform, port, and configuration; a Windows-style Envs directory is not universal. Changing this variable changes where the wrapper looks; it does not move existing environments or discover project-local folders elsewhere.
List Conda environments
If you created environments with conda, run conda env list in a terminal where Conda is available, such as an initialized shell or Anaconda Prompt. Conda is available through distributions including Anaconda and Miniconda.
The alternatives conda info --envs and conda info -e display the same environment listing; see the official conda env list reference and conda info options. The listing identifies environment locations and generally names; the active environment is marked with an asterisk. Environments created at custom paths may be identified primarily by their paths. Exact names and locations depend on your installation.
You can list environments without creating any new ones. If needed for a new project, conda create --name vEnv2 python creates a named environment containing Python; substitute your desired name. This is an unexecuted, dependency-specific instruction that can download packages and request confirmation.
Conda’s listing is not a search for all venv or virtualenvwrapper environments. If an expected Conda environment is absent, check that you are using the intended Conda installation and user account. If the command itself is unavailable, open the distribution’s prompt or initialize Conda for your shell before retrying. These manager commands are unexecuted here; no session-specific output is claimed.
List environments with workon
The workon command also comes from virtualenvwrapper. After completing the wrapper setup above, enter workon with no arguments to list the available environments in WORKON_HOME. It does not activate each environment while listing them.
Adding a name changes the operation: workon vEnv1 activates that managed environment in the current shell. Replace vEnv1 with a name from your listing. This activation form is an unexecuted instruction requiring an existing managed environment.
If workon and lsvirtualenv both omit an environment, check their shared directory configuration before recreating anything. A folder made with virtualenv vEnv1 in an arbitrary project directory does not automatically become visible to the wrapper. Use the listing method that matches the manager and location you actually used.