You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装psutil时gcc命令执行失败的技术求助

Fixing "gcc failed with exit status" When Installing psutil on macOS

First, let's recap the error context from your stack trace:

building 'psutil._psutil_osx' extension
creating build/temp.macosx-10.5-x86_64-2.7
creating build/temp.macosx-10.5-x86_64-2.7/psutil
creating build/temp.macosx-10.5-x86_64-2.7/psutil/arch
creating build/temp.macosx-10.5-x86_64-2.7/psutil/arch/osx
gcc -fno-strict-aliasing -I/Users/jspacman/miniconda/include -arch x86_64 -DNDEBUG ...
error: command 'gcc' failed with exit status

This error typically stems from missing build tools, a mismatch between your Python version and psutil's compatibility, or issues with macOS's default compiler setup. Here are actionable fixes to resolve it:

1. Install Xcode Command Line Tools (Most Common Fix)

macOS doesn’t include full build utilities out of the box. The "gcc" referenced here is actually an alias for Clang, and you’re likely missing system headers or compiler components needed to build psutil from source. Run this in your terminal:

xcode-select --install

Follow the on-screen prompts to install the tools, then retry installing psutil.

2. Use Conda’s Precompiled psutil Package

Conda maintains pre-built binaries for many packages, which skips the need to compile from source entirely—perfect for avoiding gcc-related headaches. Run this command in your Conda environment:

conda install psutil

This will pull a version of psutil pre-compiled for your macOS and Python 2.7 setup.

3. Force Pip to Use Clang (If You Need Pip Installation)

If you must install via pip, explicitly tell it to use Clang (macOS’s actual underlying compiler) instead of the "gcc" wrapper. Set these environment variables first, then run the install:

export CC=clang
export CXX=clang++
pip install psutil

4. Specify a Python 2.7-Compatible psutil Version

Python 2.7 is end-of-life, and newer psutil releases no longer support it. If you’re trying to install the latest version, it will fail to compile for Python 2.7. Instead, install a compatible older release:

pip install psutil==5.8.0

Version 5.8.0 is one of the last official psutil releases that supports Python 2.7.


内容的提问来源于stack exchange,提问作者DougKruger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:05:40