207

In virtualenvwrapper, is there a simple way to list all virtualenv on my machine?

(like what yolk -l does to list all python packages in the current virtual environment?)

CLARIFICATION: "ls -la" in my env directory does not count. I am looking for a virtualenv or virtualenvwrapper specific command.

1

14 Answers 14

201

You can use the lsvirtualenv, in which you have two options "long" or "brief":

"long" option is the default one, it searches for any hook you may have around this command and executes it, which takes more time.

"brief" just take the virtualenvs names and prints it.

brief usage:

$ lsvirtualenv -b

long usage:

$ lsvirtualenv -l

if you don't have any hooks, or don't even know what i'm talking about, just use "brief".

2
  • 25
    zsh: command not found: lsvirtualenv
    – aksyuma
    Commented Jul 12, 2022 at 11:53
  • 1
    To prevent voting people up for command not found: lsvirtualenv. Please do pip install virtualenvwrapper or use thise guide for Ubuntu
    – Leon
    Commented Nov 23, 2023 at 13:30
116

To list all the virtual environments (if using the anaconda distribution):

conda info --envs

Hope my answer helps someone...

2
  • 10
    Great answer! lsvirtualenv is not recognized as an internal or external command in my case.
    – Jianyu
    Commented Dec 8, 2020 at 13:53
  • Thank you for this answer as it solves my problem! lsvirtualenv does not work for me.
    – SamTulster
    Commented Feb 10, 2022 at 9:16
106

Silly question. Found that there's a

lsvirtualenv

command which lists all existing virtualenv.

See the command documentation.

2
85

If you are using virtualenv or Python 3's built in venv the above answers might not work.

If you are on Linux, just locate the activate script that is always present inside a env.

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

This will grab all Python virtual environments present inside your home directory.

For Mac Users, find works pretty good too

find $HOME -name "*activate" -type f

See Demo Here

7
  • 6
    This should be the top answer as it works on ubuntu with both: virtualenv as well as virtualenvwrapper.
    – Pe Dro
    Commented Sep 15, 2020 at 5:13
  • 1
    @PeDro Why should working on Ubuntu be the criterion for the best answer? What about people on other Linux distros? What about Windows users? Commented Oct 25, 2020 at 20:06
  • 1
    No, it shouldn't. The answer mentions that this works for Linux. I validated it on Ubuntu and voted for it. The accepted answer doesn't work for both: virtualenv and virtualenvwrapper. This one does. Please don't get it wrong
    – Pe Dro
    Commented Oct 26, 2020 at 2:17
  • 1
    agreed, best answer, because of flexibility and working without any setup. Commented Nov 23, 2020 at 14:19
  • 2
    i'm in ubuntu linux and locate is not installed but the find command did the job Commented Jan 1, 2022 at 5:20
70

Run workon with no argument to list available environments.

2
  • 1
    workon (without parameters) is the best way! It's a command of Virtualenvwrapper. lsvirtualenv is a command proper to Virtualenv. Commented Mar 2, 2019 at 17:50
  • workon lists all projects, but not every virtualenv will have an associated projet. Commented Jan 29, 2023 at 15:04
15

For conda created env use:

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

For virtualenvwrapper created env use:

lsvirtualenv
13

If you came here from Google, trying to find where your previously created virtualenv installation ended up, and why there is no command to find it, here's the low-down.

The design of virtualenv has a fundamental flaw of not being able to keep track of it's own created environments. Someone was not quite in their right mind when they created virtualenv without having a rudimentary way to keep track of already created environments, and certainly not fit for a time and age when most pip requirements require multi-giga-byte installations, which should certainly not go into some obscure .virtualenvs sub-directory of your ~/home.

IMO, the created virtualenv directory should be created in $CWD and a file called ~/.virtualenv (in home) should keep track of the name and path of that creation. Which is a darn good reason to use Conda/Miniconda3 instead, which does seem to keep good track of this.

As answered here, the only way to keep track of this, is to install yet another package called virtualenvwrapper. If you don't do that, you will have to search for the created directory by yourself. Clearly, if you don't remember the name or the location it was created with/at, you will most likely never find your virtual environment again...

One try to remedy the situation in windows, is by putting the following functions into your powershell profile:

# wrap virtualenv.exe and write last argument (presumably 
# your virtualenv name) to the file: $HOME/.virtualenv.
function ven { if( $args.count -eq 0) {Get-Content ~/.virtualenv } else {virtualenv.exe "$args"; Write-Output ("{0} `t{1}" -f $args[-1],$PWD) | Out-File -Append $HOME/.virtualenv }}

# List what's in the file or the directories under ~/.virtualenvs
function lsven { try {Get-Content ~/.virtualenv } catch {Get-ChildItem ~\.virtualenvs -Directory | Select-Object -Property Name } }

WARNING: This will write to ~\.virtualenv...


If you use the recommended venvlink, then you can add the following powershell function, to list your available virtual environments.

# List what's in the directories of C:\venvs\
#   - installed venvlink, with venvs in C:\venvs\
#   - venvlink uses: ~/.venvlinkrc
function lsven { Get-ChildItem -Path C:\venvs\ -Name }

This can surely be improved to automatically detect the venvlink root directory.

2
  • 1
    Really appreciate the explainer on this as this was my exact situation.
    – Poken1151
    Commented Aug 12, 2021 at 15:33
  • There is also a nice package called venvlink that not only keep track of where the files go, but allow you full control of putting all the different virtual environments in the same directory (even if you code is elsewhere) and either copy or link them to each other.
    – not2qubit
    Commented Jan 28, 2022 at 16:11
8

To list all virtualenvs

conda env list

Output:

# conda environments:
#
                         D:\Programs\Anaconda3
                         D:\Programs\Anaconda3\envs\notebook
                         D:\Programs\Anaconda3\envs\snakes
                         D:\Programs\Anaconda3\envs\snowflakes
base                  *  D:\Programs\Miniconda3
gluon                    D:\Programs\Miniconda3\envs\gluon
1
  • 6
    This will list only conda environments, not those generated by pip.
    – 7bStan
    Commented Nov 8, 2019 at 6:02
6

If using Anaconda conda env list

If using Python3 lsvirtualenv after you installed pip install virtualenvwrapper

2

Use below bash command to locate all virtual env in your system. You can modify the command according to your need to get in your desired format.

locate --regex "bin/activate"$ | sed 's/bin\/activate$//'
1
  • How do you know it belongs to pip? I can think of many apps having that in their paths and not even using python. But I guess this is better than nothing! Also there is already an answer using locate that is better because it's using the -b flag.
    – not2qubit
    Commented Apr 25, 2021 at 12:19
0

How do I find the Django virtual environment name if I forgot?. It is very Simple, you can find from the following location, if you forgot Django Virtual Environment name on Windows 10 Operating System.

c:\Users<name>\Envs<Virtual Environments>

enter image description here

0

The best answer I can find is we can check the installed python directory.

As for windows, the default directory for virtualenv and pipenv is.

/c/User/<username>/.virtualenv/

The directory(folder) inside the above directory shows all virtualenvs

Example -

ankit@ankit-PC MINGW64 ~/Desktop/study
$ ls /c/Users/ankit/.virtualenvs/
get_env_details*  postactivate*    postmkproject*     postrmvirtualenv*  predeactivate*  premkvirtualenv*  study-OwW1UW_H/
initialize*       postdeactivate*  postmkvirtualenv*  preactivate*       premkproject*   prermvirtualenv*

study-OwW1UW_H/ is the only directory and virtualenv in the above example.

-1

This works on Windows only:

If you are trying to find all envs created using virtualenv
search for "activate_this.py" or "pip-selfcheck.json"

0
-1

if you're working on windows and conda, typing conda info --envs in cmd will show all the existing virtual envirentment.

1
  • This was already mentioned.
    – gre_gor
    Commented Aug 18, 2022 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.