list all virtual environments in python

How to List All Virtual Environments in Python

Virtual Environments allow you to easily create a separate execution environment for python by installing separate copies of software and packages. Each virtual environment is an isolated container-like environment. These applications are neither interfered with nor interfere those installed outside the environment. You can maintain multiple virtual environments on a single system at the same time. This is a great way to create testing environments without affecting production ones. They are also used to test different versions of software in one place, without setting up multiple systems. But over time, it can become confusing as to how many virtual environments exist on your system. So it is advisable to list all virtual environments in Python.


How to List All Virtual Environments in Python

There are several ways to list all virtual environments in Python.


1. Using lsvirtualenv

You can use lsvirtualenv command for this purpose, if you are using virtualenvwrapper. It provides two options – long for detailed information and brief for summarized information.

$ lsvirtualenv -b # for brief
$ lsvirtualenv -l # for long

This command works if you are using virtualenvwrapper, which is a wrapper for virtualenv command used to manager virtual environments in python. It may not work with virtualenv, or even venv present by default in Python 3+.


2. Using workon

By default, developers use virtualenv command to install, activate and deactivate virtual environments. It provides a command workon that you can use to activate virtual environments. You can also use the same command without any arguments to list all virtual environments.

$ workon

Alternatively, you can also use locate command to find the activate script present in each virtual environment.

$ locate -b '\activate' | grep "/home"


3. Using Conda

If you are using Anaconda distribution of Python, you can use conda command to get a list of all virtual environments on your system.

$ conda info --envs  # or 
$ conda info -e      # or 
$ conda env list 

In this article, we have learnt several different ways to view the names of all virtual environments present in your system.

If you are using virtualenvwrapper, you can use lsvirtualenv command to get list of all virtual environments. If you are using virtualenv or venv you need to use workon command or locate command as shown above. If you are using Anaconda distribution, you can use conda command for the same.

Also read:

How to Transfer MySQL Database from One Computer to Another
How to List Installed PHP Modules in Linux
Fix “Too Many Authentication Failures” SSH Error
How to List All Virtual Hosts in Apache
How to Create Virtual Hard Disk Volume from File

Leave a Reply

Your email address will not be published.