开发者

List all virtualenv created by virtualenvwrapper

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 do开发者_如何转开发es not count. I am looking for a virtualenv or virtualenvwrapper specific command.


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


Silly question. Found that there's a

lsvirtualenv

command which lists all existing virtualenv.

See the command documentation.


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


Run workon with no argument to list available environments.


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


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.


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


If using Anaconda conda env list

If using Python3 lsvirtualenv after you installed pip install virtualenvwrapper


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$//'


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>

List all virtualenv created by virtualenvwrapper


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.


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"


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜