Is there a way to list all python virtual environments created using the venv module?

Question:

Conda allows me to list all virtual environments as shown here. The commands are:

conda info --envs OR conda env list  

I want to do that using pip. Does pip have any option to list all virtual environments created by me ? I have created a virtual environment on my desktop but I cannot figure out a way to list it along with the base environment.

Asked By: Harsha Limaye

||

Answers:

No, not in an easy way.

Python virtual environments created with venv, virtualenv and most other python-only virtual environments can be stored anywhere on the disk. And AFAIK they are not indexed, they are truly isolated (after all you can just remove venv directory and be done with it, you don’t need to do anything special). They are also unmanaged by an environment manager. So that would require entire disk scan. Which potentially can be done (you can search for all Python executables for example) but is rather painful.

It works with miniconda because miniconda manages other packages and files that it installs, so it places venvs in concrete path, e.g. /home/username/miniconda/envs/.

Answered By: freakish

The virtual environment is always going to be in the directory you are working with. all you need is to open it and activate the script. That’s all

Answered By: Cyril Berrypi

One indirect way is to run below command and see the directories where the python executable resides. Some of the paths will be python virtual environments and you can verify it by listing the files in those paths.

$ whereis python
Answered By: ebeb

You can use conda to create and manage venv and virtualenv environments and other packages installed using pip.

First create a conda environment with CONDA AND PIP installed into it, e.g.,

conda create --name core --channel conda-forge python=3.9 conda pip

Here I created the conda environment named "core" and installed Python 3.9, conda, and pip into it. So now the ‘core’ conda environment functions like an administrative environment shell. By installing conda into the conda environment, conda will track packages installed by pip into that environment. You must use "pip install" INSIDE this new conda environment, so conda will index and track those pip package installations. However, conda will still not index and centrally manage the venv environments, like it does for its own conda environments.

Here is a very good detailed guide that explains how and why to use conda and pip for virtual environments. It covers the important aspect of using conda and pip together.

Why You Need Python Environments and How to Manage Them with Conda

Create virtual environments for python with conda

Answered By: Rich Lysakowski PhD