树莓派 - psutil安装错误

9

我正在尝试在我的树莓派上安装psutil,但似乎无法正常运行。如果我执行pip install,就会出现以下错误:

psutil/_psutil_linux.c:10:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /usr/bin/python -c "import
setuptools;__file__='/home/pi/build/psutil/setup.py';exec(compile(open(__file__).read().replace('\r\n ', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-V39ila-record/install-record.txt failed with error code 1 in /home/pi/build/psutil
Storing complete log in /root/.pip/pip.log

如果我在安装文件所在目录尝试运行python setup.py build,则会出现以下错误:
psutil/_psutil_linux.c:10:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

如果有人能帮我安装这个,那就太好了。

1个回答

28

你还需要安装Python开发头文件。在Debian(Raspbian“ wheezy”)上,安装python-dev软件包:

sudo apt-get install python-dev

或者运行:

sudo apt-get build-dep python

并且获取一些在编译Python C扩展时非常有用的软件包。在最近的Debian发行版中,将python替换为python3

在Fedora(Pidora)上,相当于上一个命令的是:

sudo yum install yum-utils
sudo yum-builddep python

如果你的系统更加新,那么你可能希望将python替换为python3


对于 sudo apt-get build-dep python 命令,您需要确保在源列表中有一些源 URI。否则,非常好的答案。 - Martin Haeberli
我也因为树莓派的问题而来到这里。这个解决方案很好地解决了我的问题。 - ChrisCantrell
3
如果你最近遇到了和我一样的问题,你可能需要输入 sudo apt-get install python3-dev - Alex028502

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接