我的操作系统是 OSX 10.10.4,我同时拥有 python2.7.10 和 python3.5,并尝试为这两个版本的 python 安装 numpy、scipy 和 matplotlib。
在 python2 中一切顺利,但对于 python3,我尝试使用命令安装 numpy
pip3 install numpy
后来发现是因为找不到文件Python.h导致安装终止,但实际上python3.5的目录下确实存在文件python.h。所以我现在很困惑。
9 月 18 日更新,确切的错误消息: 最初它试图构建 numpy:
compile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -c'
clang: _configtest.c
_configtest.c:1:10: fatal error: 'Python.h' file not found
#include <Python.h>
^
1 error generated.
_configtest.c:1:10: fatal error: 'Python.h' file not found
#include <Python.h>
^
1 error generated.
failure.
removing: _configtest.c _configtest.o
Running from numpy source directory.
/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'define_macros'
warnings.warn(msg)
.....
File "numpy/core/setup.py", line 293, in check_types
"Cannot compile 'Python.h'. Perhaps you need to "\
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
----------------------------------------
Failed building wheel for numpy
Failed to build numpy
然后安装报同样的错误。
最佳答案
根据 this page这在 numpy 的 1.9.3 版本中得到修复。尝试
pip3 install numpy==1.9.3
关于python - 在 OS X 上安装 numpy 时 pip3 找不到 Python.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32635589/