1
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.To initialize your shell, run$ conda init <SHELL_NAME>
這個錯誤提示表示你的shell未被正確配置以使用conda activate
。為了解決這個問題,你需要初始化你的shell。可以按照以下步驟操作:
-
首先,你需要找出你正在使用的shell的名稱。在Terminal中,輸入
echo $0
(如果你在Unix/Linux系統下)或echo %COMSPEC%
(如果你在Windows下)。這條命令會返回你當前正在使用的shell的名稱,如bash
、zsh
、csh
、fish
、tcsh
、xonsh
、dash
、ksh
、cmd
等。 -
然后,根據返回的shell名稱,運行
conda init <SHELL_NAME>
。例如,如果你正在使用bash shell,你應該運行conda init bash
。 -
最后,重啟你的Terminal窗口,或者關閉并重新打開PyCharm。
這些步驟應該可以解決你遇到的問題。如果問題仍然存在,你可能需要檢查你的PATH變量是否包含了conda的路徑,或者嘗試重新安裝Anaconda。
2
ArgumentError: Invalid shells: - Local
Currently available shells are:- bash- cmd.exe- fish- powershell- tcsh- xonsh- zsh
該錯誤提示表明你嘗試初始化的shell名稱無效。根據你的系統提示,有效的shell名稱包括:bash
、cmd.exe
、fish
、powershell
、tcsh
、xonsh
和zsh
。
假設你在Windows系統上,你應該使用cmd.exe
或powershell
。所以,你應該運行以下命令之一:
conda init cmd.exe
或
conda init powershell
然后,你需要重新啟動你的Terminal窗口,或者關閉并重新打開PyCharm。這應該會解決你遇到的問題。
3 換成清華源
你可以通過修改conda的配置文件來完成這個任務。conda的配置文件通常位于用戶的主目錄下,名為.condarc
。請按照以下步驟操作:
-
打開終端。
-
輸入以下命令打開.condarc文件:
Linux/macOS:
nano ~/.condarc
Windows:
notepad %USERPROFILE%\.condarc
-
修改文件內容,使其看起來像下面這樣:
channels:- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/- defaults
show_channel_urls: true
default_channels:- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudmsys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudbioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudmenpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudpytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudsimpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- 保存并關閉文件。
完成以上步驟后,你的conda源就已經被設置為清華的源了。當你下次使用conda來安裝包時,它將會從你指定的清華源來下載和安裝。
5.查看源
你可以通過以下命令查看你的conda配置,包括你設置的所有源(channels):
conda config --show
在顯示的配置信息中,找到名為 channels
的部分,這部分列出了你當前設置的所有conda源。這些源將按照列出的順序被搜索,所以如果你有多個源,conda會首先從第一個源開始搜索需要的包。
4命令行換成清華源
如果你在中國或者你可以更快地訪問清華大學的鏡像服務器,你可以將conda的源更改為清華大學的鏡像源,這樣在下載和安裝包時可以獲得更快的速度。
以下是如何更改conda源的步驟:
- 在終端中運行以下命令添加清華大學的Anaconda鏡像源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- 添加清華大學的Anaconda云鏡像源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- 設置搜索時顯示通道地址:
conda config --set show_channel_urls yes
現在,當你使用conda下載和安裝包時,它會優先從清華大學的鏡像源下載。
請注意,由于網絡問題或鏡像服務器的狀態,清華大學的鏡像源可能會暫時無法訪問。在這種情況下,你可以嘗試使用其他的鏡像源,例如中科大的鏡像源。