Harsha Limaye
Harsha Limaye

Reputation: 1143

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

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.

Upvotes: 8

Views: 34660

Answers (4)

Alferd Nobel
Alferd Nobel

Reputation: 3979

To list all the venv directories in the current directory and its subdirectories, you can try this :

find . -type d -name "*.venv"

Upvotes: 0

Rich Lysakowski PhD
Rich Lysakowski PhD

Reputation: 3113

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

Upvotes: 0

freakish
freakish

Reputation: 56527

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/.

Upvotes: 8

ebeb
ebeb

Reputation: 519

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

Upvotes: 1

Related Questions