安裝
根據搜索結果,以下是使用Homebrew在macOS上安裝Miniconda的詳細步驟:
1.安裝Homebrew(如果尚未安裝)
打開終端(Terminal),運行以下命令安裝Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2.使用Homebrew安裝Miniconda
在終端中運行以下命令安裝Miniconda:
brew install --cask miniconda
3.初始化Conda
安裝完成后,需要初始化Conda。運行以下命令:
conda init "$(basename "${SHELL}")"
這會根據你當前使用的shell(如bash或zsh)來初始化Conda。
4.重新加載Shell配置
為了使更改生效,需要重新加載你的shell配置文件。如果你使用的是zsh,可以運行:
source ~/.zshrc
如果你使用的是bash,可以運行:
source ~/.bash_profile
5.驗證安裝
在終端中運行以下命令驗證Conda是否安裝成功:
conda --version
如果顯示版本號(如conda 23.7.4
),則說明安裝成功。
6.配置環境變量(如果需要)
如果終端無法識別conda
命令,可能需要手動配置環境變量。運行以下命令:
echo 'export PATH="/opt/homebrew/Caskroom/miniconda/base/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
或者,如果你使用的是bash:
echo 'export PATH="/opt/homebrew/Caskroom/miniconda/base/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
7.創建和管理環境
現在你可以使用Conda來創建和管理虛擬環境了。例如,創建一個名為myenv
的虛擬環境,并指定Python版本為3.10:
conda create --name myenv python=3.10
激活該環境:
conda activate myenv
8.配置國內源(可選)
為了提高下載速度,可以配置國內源。運行以下命令:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --set show_channel_urls yes
9.關閉默認激活base環境(可選)
如果你不想每次打開終端時自動激活base
環境,可以運行以下命令:
conda config --set auto_activate_base false
通過以上步驟,你可以在macOS上使用Homebrew成功安裝并配置Miniconda。如果遇到問題,可以參考Conda官方文檔或社區支持。
使用
1.創建環境
conda create -n cbf310 python=3.10conda init "$(basename "${SHELL}")"
2.激活環境
conda activate cbf310
3.安裝依賴
pip3 install -r requirements.txt
4.退出
conda deactivate
在激活的環境中安裝包:
conda install numpy pandas
conda uninstall numpy
查看當前環境中已安裝的包:
conda uninstall numpy
更新特定包:
conda update numpy
刪除不再需要的虛擬環境:
conda env remove --name myenv
為了提高下載速度,可以配置國內源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
搜索可用的包:
conda search numpy
查看所有已創建的虛擬環境:
conda env list
導出當前環境的依賴列表:
conda env export > environment.yml