如何使用 Python 子进程在 linux 中激活 conda 虚拟环境

问题描述

我只是想在 linux 中使用 python 激活 conda 虚拟环境。我正在使用子流程模块。当我在终端中使用 conda activate 时它工作正常,但这在 pyhton 中似乎不起作用。我的代码

subprocess.run('conda activate ENV_NAME',shell=True)

但是当我执行这个简单的代码时,出现以下错误

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell,run

    $ conda init <SHELL_NAME>

    Currently supported shells are:
      - bash
      - fish
      - tcsh
      - xonsh
      - zsh
      - powershell
    
    See 'conda init --help' for more information and options.
    
    IMPORTANT: You may need to close and restart your shell after running 'conda init'.

请帮帮我,我该怎么办?尝试了 stackoverflow 中的所有解决方案,但仍然出现相同的错误。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)