How can I list all the virtual environments created with venv?

后端 未结 1 1829
生来不讨喜
生来不讨喜 2020-12-11 20:51

Someone\'s just asked me how to list all the virtual environments created with venv.

I could only think of searching for pyvenv.cfg files to find them.

相关标签:
1条回答
  • 2020-12-11 21:02

    On Linux/macOS this should get most of it

    find ~ -d -name "site-packages" 2>/dev/null

    Looking for directories under your home that are named "site-packages" which is where venv puts its pip-installed stuff. the /dev/null bit cuts down on the chattiness of things you don't have permission to look into.

    Or you can look at the specifics of a particular expected file. For example, activate has nondestructive as content. Then you need to look for a pattern than matches venv but not anaconda and the rest.

    find ~ -type f -name "activate" -exec egrep -l nondestructive /dev/null {} \; 2>/dev/null

    0 讨论(0)
提交回复
热议问题