我有一个使用的脚本os.system(cmd)
运行管道。我需要管道在特定的 Conda 环境中运行,所以我尝试执行以下操作:
cmd = 'conda activate base && ' + cmd
os.system(cmd)
但是,我得到:
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'.
事实是,我的 shell 已正确配置。如果我运行同样的cmd
在 shell 中,一切都按预期进行。
我尝试过使用subprocess.run(cmd, shell=True)
也是如此,但我得到了相同的结果。
有没有办法跑conda activate base
从 python 脚本中?
conda activate
实际上是为了在交互式设置(shell/命令提示符)中使用。但你可以使用conda run
在给定环境中执行特定的 python 脚本。
试试这个:
conda run -n <environment> <script_name>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)