33

I have more than one Python environment configured in my Debian OS. Is there a way to list all configured environments in Linux?

This is different from the possible duplicate as indicated in the comment below. I mean virtual environments created using virtualenv only.

de1
  • 2,986
  • 1
  • 15
  • 32
AhmedWas
  • 1,205
  • 3
  • 23
  • 38
  • 3
    `whereis python` gives you a nice list – Darth Kotik Sep 28 '16 at 10:43
  • Thanks for the answer. However, this gave me all different installed versions of python, but not the virtual environments. – AhmedWas Sep 28 '16 at 10:47
  • 1
    The command `lsvirtualenv -l` in the duplicate question you are referring to, gives me `command not found`. – AhmedWas Sep 28 '16 at 11:01
  • 3
    Define what do you mean by "python environment". Do you mean virtual environments created using `virtualenv` only? Both these and other python installations? Different python installations (but no virtual envs)? AFAIK `virtualenv` does **not** keep track of all the envs you create and as such there's no built-in way to do what you want. The `lsvirtualenv` command is part of the [`virtualenvwrapper`](https://virtualenvwrapper.readthedocs.io/en/latest/) program which adds some functionality to virtualenv. You'll have to use `find` and look for specific files that are created by virtualenv. – Bakuriu Sep 28 '16 at 12:11
  • Yes, I mean virtual environments created using `virtualenv` only. – AhmedWas Sep 28 '16 at 12:17
  • This is also true for windows. – not2qubit Oct 25 '20 at 20:57

1 Answers1

41

If only using the lowly virtualenv ...{directory} to create a virtualenv, then there is just some directory somewhere that has that specific environment in it. You can only "list" these by running find on your $HOME directory (or any other list of directories you might have used to create virtualenvs) looking for python installations. Hopefully some convention was followed like storing them all in ~/virtualenvs. (See also Where should virtualenvs be created? )

If using virtualenvwrapper, then as mentioned, use the command lsvirtualenv to list envs that were created with mkvirtualenv. They are all in ~/.virtualenvs by default. See https://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html

If using conda, you can list virtual envs created via conda create --name {my_env} [...], using either conda info --envs or conda env list. See https://conda.io/docs/using/envs.html#list-all-environments

michael
  • 9,161
  • 2
  • 52
  • 49
  • 12
    My god! Who in their right mind created `virtualenv` without having a rudimentary way to keep track of already created environments? And who in their right mind would wan't to keep all their gigabyte created pip envs in their *home* under a `.virtualenv` sub-directory? IMHO, the created virtualenv *directory* should be created in `$CWD` and a file called `~/.virtualenvs` (in *home*) should keep track of the name and path of that creation. – not2qubit Oct 25 '20 at 20:54
  • 2
    @not2qubit I think it is sometimes beneficial to do the opposite: put all the virtual environments to a common folder and just a link to the virtual environment in the project folder. This way, if you have automatic backups (meaning Dropbox or OneDrive on Windows, for example), the virtual environment files are not backed up unnecessarily. This way it is also possible to reuse virtual environments. I have created even a simple package to make this easier and so far have liked the arrangement. – Niko Föhr Jan 02 '21 at 17:57
  • 1
    @np8 Yes, your [venvlink](https://github.com/np-8/venvlink) look promising. – not2qubit Jan 31 '21 at 12:57