201

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.

Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167

14 Answers14

197

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

Bengineer
  • 7,264
  • 7
  • 27
  • 28
111

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

conda info --envs

Hope my answer helps someone...

Kyle
  • 1,070
  • 2
  • 13
  • 23
Michael Yadidya
  • 1,397
  • 1
  • 9
  • 15
101

Silly question. Found that there's a

lsvirtualenv

command which lists all existing virtualenv.

See the command documentation.

Tms91
  • 3,456
  • 6
  • 40
  • 74
Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167
  • 2
    see the command reference http://www.doughellmann.com/docs/virtualenvwrapper/command_ref.html – zack Mar 17 '12 at 20:03
  • @Tms91 documentation is now here :) https://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html#lsvirtualenv – zack Nov 03 '22 at 16:17
78

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

Bhupesh Varshney
  • 1,522
  • 14
  • 19
  • 6
    This should be the top answer as it works on ubuntu with both: `virtualenv` as well as `virtualenvwrapper`. – Pe Dro Sep 15 '20 at 05: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? – snakecharmerb Oct 25 '20 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 Oct 26 '20 at 02:17
  • 1
    agreed, best answer, because of flexibility and working without any setup. – dreamflasher Nov 23 '20 at 14:19
  • 1
    This works for OS X, where the above answers did not work for me with `virtualenv` – Jeff Benshetler Dec 08 '21 at 16:51
  • 2
    i'm in ubuntu linux and `locate` is not installed but the `find` command did the job – ErichBSchulz Jan 01 '22 at 05:20
70

Run workon with no argument to list available environments.

ESV
  • 7,620
  • 4
  • 39
  • 29
14

For conda created env use:

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

For virtualenvwrapper created env use:

lsvirtualenv
not2qubit
  • 14,531
  • 8
  • 95
  • 135
Pygirl
  • 12,969
  • 5
  • 30
  • 43
11

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.

not2qubit
  • 14,531
  • 8
  • 95
  • 135
  • 1
    Really appreciate the explainer on this as this was my exact situation. – Poken1151 Aug 12 '21 at 15:33
  • There is also a nice package called [**`venvlink`**](https://github.com/np-8/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 Jan 28 '22 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
LF00
  • 27,015
  • 29
  • 156
  • 295
6

If using Anaconda conda env list

If using Python3 lsvirtualenv after you installed pip install virtualenvwrapper

Sean
  • 680
  • 7
  • 10
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$//'
dheeraj
  • 368
  • 2
  • 8
  • 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 Apr 25 '21 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

Eranda J.
  • 490
  • 5
  • 7
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"

Shyam R
  • 126
  • 1
  • 6
-1

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

Baya Lina
  • 457
  • 4
  • 11