List all virtualenv
-
14-01-2021 - |
Question
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.
La solution 2
Silly question. Found that there's a
lsvirtualenv
command which lists all existing virtualenv.
Autres conseils
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".
To list all the virtual environments (if using the anaconda distribution):
conda info --envs
Hope my answer helps someone...
Run workon with no argument to list available environments.
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.
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
For conda created env use:
conda info --envs # or
conda info -e # or
conda env list
For virtualenvwrapper created env use:
lsvirtualenv
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
...
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"