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 芯片。

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

相关推荐
Patrick在香港3 小时前
同一份脚本,mac 正常 Windows 乱码:open() 默认编码实测(附 3.15 终局)
utf-8·windows·python·macos·跨平台·编码·标准库
DevLoom_5 小时前
Mac装NTFS for Mac,不用修改 SIP 安全设置也能正常读写NTFS硬盘
macos·macos 27·mac读写ntfs·ntfs for mac·mac应用
Laurie三省5 小时前
现场版却配上录音室版的歌词?聊聊我给开源 Mac 歌词软件写的多源打分算法
算法·macos·go
David@6 小时前
Mac中cursor怎么检查更新
macos
emo_2b1 天前
Pycharm配置conda解释器时遇到的问题及解决方法
linux·pycharm·conda
Lancker1 天前
没有 Mac 也能上架 iOS:GitHub Actions 全自动构建 + 签名 + TestFlight 送审实录
macos·ios·github
fei_sun2 天前
RIB、FIB、MAC 、ARP 表
服务器·网络·macos
Highcharts.js2 天前
如何在macOS桌面应用集成Highcharts
macos·highcharts·前端可视化·交互图表
zaemyn20202 天前
macOS 上 AccessClient 无法唤起?排查 Python 架构与 Windows App 识别问题
windows·python·macos·远程桌面·accessclient
Είναι η κοπέλα3 天前
llama.cpp 与 GGUF 格式:本地大模型的“裸引擎“
开发语言·人工智能·pytorch·python·conda