List all virtualenv created by virtualenvwrapper
Asked Answered
M

14

206

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.

Monometallic answered 27/8, 2011 at 2:20 Comment(1)
M
105

Silly question. Found that there's a

lsvirtualenv

command which lists all existing virtualenv.

See the command documentation.

Monometallic answered 18/9, 2011 at 18:50 Comment(2)
see the command reference doughellmann.com/docs/virtualenvwrapper/command_ref.htmlSublime
@Tms91 documentation is now here :) virtualenvwrapper.readthedocs.io/en/latest/…Sublime
E
200

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

Ellita answered 23/4, 2012 at 22:17 Comment(2)
zsh: command not found: lsvirtualenvWolfgang
To prevent voting people up for command not found: lsvirtualenv. Please do pip install virtualenvwrapper or use thise guide for UbuntuCritchfield
U
114

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

conda info --envs

Hope my answer helps someone...

Uncharted answered 4/4, 2018 at 4:57 Comment(2)
Great answer! lsvirtualenv is not recognized as an internal or external command in my case.Altaf
Thank you for this answer as it solves my problem! lsvirtualenv does not work for me.Innovation
M
105

Silly question. Found that there's a

lsvirtualenv

command which lists all existing virtualenv.

See the command documentation.

Monometallic answered 18/9, 2011 at 18:50 Comment(2)
see the command reference doughellmann.com/docs/virtualenvwrapper/command_ref.htmlSublime
@Tms91 documentation is now here :) virtualenvwrapper.readthedocs.io/en/latest/…Sublime
J
83

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

Jard answered 27/6, 2020 at 8:46 Comment(6)
This should be the top answer as it works on ubuntu with both: virtualenv as well as virtualenvwrapper.Raster
@PeDro Why should working on Ubuntu be the criterion for the best answer? What about people on other Linux distros? What about Windows users?Calen
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 wrongRaster
agreed, best answer, because of flexibility and working without any setup.Indicant
This works for OS X, where the above answers did not work for me with virtualenvBookplate
i'm in ubuntu linux and locate is not installed but the find command did the jobExcoriation
C
70

Run workon with no argument to list available environments.

Chacon answered 6/8, 2012 at 16:0 Comment(2)
workon (without parameters) is the best way! It's a command of Virtualenvwrapper. lsvirtualenv is a command proper to Virtualenv.Voidance
workon lists all projects, but not every virtualenv will have an associated projet.Calen
A
15

For conda created env use:

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

For virtualenvwrapper created env use:

lsvirtualenv
Aye answered 8/11, 2019 at 18:0 Comment(0)
G
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.

Grimy answered 25/10, 2020 at 21:14 Comment(2)
Really appreciate the explainer on this as this was my exact situation.Prepare
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.Grimy
C
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
Convergent answered 21/10, 2019 at 11:21 Comment(1)
This will list only conda environments, not those generated by pip.Ranna
V
6

If using Anaconda conda env list

If using Python3 lsvirtualenv after you installed pip install virtualenvwrapper

Vicereine answered 11/8, 2021 at 12:53 Comment(0)
T
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$//'
Terrell answered 3/2, 2021 at 12:41 Comment(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.Grimy
A
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

Alexipharmic answered 9/11, 2020 at 2:2 Comment(0)
U
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.

Unroot answered 30/7, 2022 at 11:51 Comment(0)
O
-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"

Octofoil answered 29/5, 2019 at 12:49 Comment(0)
B
-1

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

Boyles answered 3/11, 2021 at 13:22 Comment(1)
This was already mentioned.Atman

© 2022 - 2024 — McMap. All rights reserved.