如果我跑步
xterm -hold
并且在新输入的终端中
conda activate my_environment
conda环境“ my_environment”确实已激活。
但是,当使用-e标志传递此命令时,它不起作用:
xterm -hold -e "conda activate my_environment"
它返回以下错误消息:
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'.
因此,如何使用xterm完成此操作?还是应该使用其他类型的外部端子?
conda activate
命令是一个外壳函数,在外壳初始化期间定义。 conda init
将代码添加到初始化文件(例如.bash_profile
),以运行定义conda activate
Shell函数的脚本。
xterm
选项-c
参数与xterm
一起使用时,它将不再运行初始化脚本。因此,conda activate
从未定义。对于bash
,有-l
告诉它运行初始化文件。我期望xterm的-ls
参数会触发类似的行为,但对我而言不起作用。也许更熟悉的人可以将您指向正确的标志。
否则,您只需要自己运行Conda脚本(假设它是bash版本)。这些都可以工作:
xterm -hold -e ". /path/to/miniconda3/etc/profile.d/conda.sh && conda activate my_environment && which python"
或
xterm -hold -e "$(conda shell.bash hook) && conda activate my_environment && which python"
仅包含which python
以表明您已激活环境。
另一个选项是conda run
,它可以在环境下自动执行命令。以下内容与我在上一节中所做的等效,但是不必知道我在哪个shell中运行:
xterm -hold -e "conda run -n my_environment which python"