macOS 上安装 Miniconda + Conda-Forge

1. 下载 Miniconda

打开终端(Terminal),运行以下命令下载最新版 Miniconda(适用于 Intel 和 Apple Silicon 芯片):

bash 复制代码
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh

如果是 Apple Silicon(M1/M2 芯片),改用:

bash 复制代码
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh

2. 安装 Miniconda

运行安装脚本并按照提示操作:

bash 复制代码
bash Miniconda3-latest-MacOSX-*.sh
  • 安装选项

    • Enter 查看许可协议,输入 yes 同意。

    • 安装路径:默认 ~/miniconda3(推荐)。

    • 是否初始化 Conda:输入 yes(会将 Conda 添加到 ~/.zshrc~/.bash_profile)。

3. 激活 Conda

关闭并重新打开终端,或运行以下命令激活 Conda:

bash 复制代码
source ~/.zshrc  # 如果使用 Zsh(macOS 默认)
# 或
source ~/.bash_profile  # 如果使用 Bash

验证安装:

bash 复制代码
conda --version

应输出类似 conda 24.1.2 的版本号。

4. 配置 Conda-Forge 为默认仓库

移除默认频道(避免商业仓库):

bash 复制代码
conda config --remove-key channels

添加 Conda-Forge 并设置优先级:

bash 复制代码
conda config --add channels conda-forge
conda config --set channel_priority strict

验证配置:

bash 复制代码
conda config --show channels

输出应为:

bash 复制代码
channels:
  - conda-forge

5. 创建并激活环境

创建一个新环境(例如名为 myenv,Python 3.10):

bash 复制代码
conda create -n myenv python=3.10

激活环境:

bash 复制代码
conda activate myenv

6. 安装开源包

通过 Conda-Forge 安装常用包:

bash 复制代码
conda install numpy pandas matplotlib jupyter scikit-learn

7. 验证安装

检查包的来源是否为 Conda-Forge:

bash 复制代码
conda list

输出中的 Channel 列应显示 conda-forge

8. 可选:配置国内镜像加速

如果下载速度慢,可添加清华镜像:

bash 复制代码
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

9. 卸载 Miniconda(如需)

删除整个安装目录:

bash 复制代码
rm -rf ~/miniconda3

然后编辑 ~/.zshrc~/.bash_profile,删除 Conda 相关的初始化代码。

常见问题

1. Apple Silicon(M1/M2)兼容性
  • Conda-Forge 已原生支持 ARM64 架构,安装时选择 MacOSX-arm64.sh 即可。

  • 如果遇到某些包不兼容,可通过 Rosetta 2 运行 Intel 版本:

bash 复制代码
softwareupdate --install-rosetta  # 安装 Rosetta 2
arch -x86_64 bash  # 启动 Intel 模式终端

然后在 Intel 模式下重复安装步骤。

2. 安装后 Conda 命令未生效

如果终端提示 conda: command not found,手动初始化:

bash 复制代码
source ~/miniconda3/bin/activate
conda init zsh  # 或 bash

总结

  • Miniconda 提供最小化的 Conda 环境,Conda-Forge 确保完全开源。

  • 适用于 macOS Intel 和 Apple Silicon 芯片。

  • 通过国内镜像可大幅提升下载速度。

相关推荐
我不是小upper9 小时前
anaconda、conda、pip、pytorch、torch、tensorflow到底是什么?它们之间有何联系与区别?
人工智能·pytorch·深度学习·conda·tensorflow·pip
可曾去过倒悬山16 小时前
mac操作笔记
macos
可曾去过倒悬山16 小时前
Mac上优雅简单地使用Git:从入门到高效工作流
git·elasticsearch·macos
山楂树の20 小时前
模型优化——在MacOS 上使用 Python 脚本批量大幅度精简 GLB 模型(通过 Blender 处理)
python·macos·3d·图形渲染·blender
MobiCetus1 天前
确保conda环境内的Py不会污染系统
chrome·python·conda
光头才能变强1 天前
Mac安装Navicat教程Navicat Premium for Mac v17.1.9 Mac安装navicat【亲测】
macos
Frilled Lizard1 天前
解决mac下git pull、push需要输入密码
git·macos
是小崔啊1 天前
Mac下的Homebrew
macos
冰镇西瓜2 天前
windows本地使用conda部署Open-webui
windows·ai·conda
SiYuanFeng2 天前
【问题未解决-寻求帮助】VS Code 中使用 Conda 环境,运行 Python 后 PowerShell 终端输出内容立即消失
开发语言·python·conda