gpt4 book ai didi

Python - 通过shell脚本激活conda env

转载 作者:行者123 更新时间:2023-12-02 03:49:46 25 4
gpt4 key购买 nike

我希望运行一个简单的 shell 脚本来简化一些 conda 环境的管理。在 linux 操作系统中通过 conda activate 激活 conda 环境在 shell 中工作正常,但在 shell 脚本中存在问题。有人能指出我正确的方向来解释为什么会发生这种情况吗?

重复问题的示例:

# default conda env
$ conda info | egrep "conda version|active environment"
active environment : base
conda version : 4.6.9

# activate new env to prove that it works
$ conda activate scratch
$ conda info | egrep "conda version|active environment"
active environment : scratch
conda version : 4.6.9

# revert back to my original conda env
$ conda activate base

$ cat shell_script.sh
#!/bin/bash
conda activate scratch

# run shell script - this will produce an error even though it succeeded above
$ ./shell_script.sh

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 脚本,它有效:

source shell_script.sh

关于Python - 通过shell脚本激活conda env,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55507519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com