Conan 在 macOS 上安装后命令不可用,主因是 SIP 限制、PATH 未配置及 profile 未正确检测;需执行 pip install --user conan 后将 ~/Library/Python/X.Y/bin 加入 PATH,并运行 conan profile detect --force 确保架构与编译器匹配。

Conan 在 macOS 上能用,但默认安装路径、Python 环境和系统保护机制会让 conan 命令直接不可用——不是装失败,而是找不到命令。
macOS 上 conan 命令找不到的典型现象
执行 conan --version 报错 command not found: conan,哪怕 pip install conan 显示成功。这是因为:
- macOS SIP(System Integrity Protection)会阻止向系统级
/usr/bin写入,而pip install默认尝试写入受保护路径 -
pip install --user conan会把可执行文件放到~/Library/Python/X.Y/bin/,但该路径不在默认$PATH中 - Homebrew 安装虽方便,但某些版本(如 Apple Silicon 上)可能链接头文件路径不一致,导致 CMake 找不到
nlohmann/json.hpp这类头文件
用 brew install conan 时 xcode-select --install 是必须的
Homebrew 依赖 Xcode Command Line Tools 提供 clang、make 和 pkg-config 等基础工具。不装它,brew install conan 会卡在 python@3.10: the bottle needs the Apple Command Line Tools to be installed 错误。
执行后验证:
sudo xcode-select --install
装完后运行:
brew install conan
再确认是否生效:
conan --version
如果仍报 command not found,请检查 brew --prefix 输出,并确保其下的 bin 目录已加入 $PATH(通常 brew 会提示你加,没提示就手动在 ~/.zshrc 里加一行:export PATH="$(brew --prefix)/bin:$PATH")
pip install conan --user 后 PATH 不生效怎么办
这是 macOS 最常踩的坑:装是装上了,但 shell 找不到 conan 可执行文件。
先确认安装位置:
python -m site --user-base
输出类似 /Users/xxx/Library/Python/3.12,那 conan 实际在:
/Users/xxx/Library/Python/3.12/bin/conan
把它加进 $PATH:
- 编辑
~/.zshrc(macOS Catalina 及以后默认 shell 是 zsh) - 追加:
export PATH="$HOME/Library/Python/3.12/bin:$PATH"(注意把3.12换成你实际 Python 版本) - 运行
source ~/.zshrc
再试 conan --version。如果还失败,检查是否漏了 chmod +x ——极少数情况下权限被重置,可手动修复:chmod +x ~/Library/Python/3.12/bin/conan
profile detect --force 必须运行,否则后续构建会出 ABI 错误
macOS 的编译器(apple-clang)、架构(x86_64 或 arm64)、SDK 路径都得让 Conan 显式感知,否则 conan install 会拉错二进制包,比如给 M1 Mac 装了 x86_64 的 zlib,链接时报 file was built for archive which is not the architecture being linked。
正确做法:
conan profile detect --force
它会生成 ~/.conan/profiles/default,内容包含:
[settings] os=Macos os.version=14 arch=arm64 compiler=apple-clang compiler.version=15 compiler.libcxx=libc++ build_type=Release
如果你用的是 Intel Mac,arch 应为 x86_64;若未自动识别,可手动编辑该文件,或加参数指定:conan profile detect --force --name=default --os=Macos --arch=x86_64
真正麻烦的不是装不上,而是装上后 profile 没对、PATH 没导、架构没识别——这三处任意一个出错,conan install 都可能静默成功但最终链接失败,且错误信息完全不提 Conan。


















