'conda env list' 从里面 Python shell

'conda env list' from inside Python shell

我知道我可以通过在 unix 终端上键入 'conda env list' 来查找 conda 环境列表。但是,我希望从 Python shell 中删除它(因为我需要知道是否已经创建了某些 conda 环境)。为了提供一些额外的背景,我使用 Python 3+ .

到目前为止,我已经尝试过:

subprocess.check_output('conda env list')

但是,我收到以下错误:

FileNotFoundError: [Errno 2] No such file or directory: 'conda env list'

我尝试了其他方法将 'conda evn list' 写入终端,但一直出现相同的错误。

我成功了:

ret = subprocess.check_output('conda env list', shell=True)
print ret

警告:仅使用 2.7

进行测试