[英]Silence Conda Shell Warning
當我在 Bash 腳本中激活 Conda 環境時,例如:
#!/bin/bash
conda activate ./myenv
which python
python do_stuff.py
激活行打印出長警告:
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'.
如何使此警告靜音? 如果我運行它建議的conda init bash
命令,這會導致 Conda 默認為所有 Bash shell 激活我的環境,這絕對不是我想要的。 這是 Conda 中的默認配置,在它破壞了我系統中各處的功能后,我明確將其關閉。 我希望 Conda 到 function 類似於 virtualenv,其中我有一個包含環境的文件夾,並且僅在特定應用程序需要時才激活它。 在任何情況下,我都不希望為在我系統上的任何位置運行的每個 Bash 實例激活 Conda 環境。
我不知道為什么它給了我一個 CommandNotFoundError,否則 Conda 會填充我的 Bash shell 以及 ZA7F5F35426B927411FC9231B5638217Z 的正確路徑,並且其他所有環境特定資源都可以正常工作。
在腳本中添加以下代碼。
eval "$(command conda 'shell.bash' 'hook' 2> /dev/null)"
這僅在腳本中初始化 conda。
初始化conda
后,默認情況下,它將在您打開的每個新 shell session 上自動激活基本環境。 如果您想關閉此行為,只需運行一次:
conda config --set auto_activate_base false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.