3

I know in conda I can use conda env list to get a list of all conda virtual environments, what's the corresponding command in python venv that can list all the virtual environments in a given venv? also, is there any way I can print/check the directory of current venv? somehow I have many projects that have same name .venv for their virtual environment and I'd like to find a way to verify which venv I'm in. Thanks

JamesWang
  • 1,175
  • 3
  • 14
  • 32
  • Probably this would help you answer your questions: https://stackoverflow.com/questions/39745143/how-to-list-all-python-virtual-environments-in-linux – stark Dec 01 '19 at 04:37
  • @stark9190 the link answers how to list environments created by `virtualenv` (python2). But what is the command for listing environments created by `venv` (python3)? – MJimitater Apr 29 '20 at 12:27
  • Does this answer your question? [How can I list all the virtual environments created with venv?](https://stackoverflow.com/questions/60873454/how-can-i-list-all-the-virtual-environments-created-with-venv) – sinoroc Apr 29 '20 at 12:44

3 Answers3

3

Virtual environments are simple a set of files in a directory on your system. You can find them the same way you would find images or documents with a certain name. For example, if you are using Linux or macOS, you could run find / | grep bin/activate in terminal. Not too sure about Windows but I suspect you can search for something similar in Windows Explorer.

Python Newbie
  • 317
  • 2
  • 9
1

I'm relatively new to python venv as well. I have found that if you created your virtual environment with python -m venv <yourvenvname> with in a project folder.

I'm using windows, using cmd, for example, you have a Dash folder located in C:\Dash, when you created a venv called testenv by

python -m venv testenv,

you can activate the virtual environment by just input

C:\Dash\testenv\Scripts\activate,

then you can deactivate it by just type in deactivate.

If you want to list the venv that you have, you go to the C:\Dash folder. type

dir

in cmd, it will list the list of the virtual env you have, similar to conda env list. if you want to delete that virtual env, simply do

rm -rf testenv

you can list the packages installed within that venv by doing

pip freeze.

I hope this helps. please correct me if I'm wrong.

stoneshishang
  • 433
  • 4
  • 11
0

Simply use lsvirtualenv in the parent directory in CMD. This will show the list of all venv. if you want to open a specific one from the listed type workon(env_name). Then hit Enter