python - 在 OS X 上安装 numpy 时 pip3 找不到 Python.h

标签 python macos numpy

我的操作系统是 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/

相关文章:

python - 如何以彩色显示 tiff 文件?

python - python中数值数组的stepify/grid snap函数

python - 如何使用 `pip install git+ssh` 安装附加功能?

macos - OpenGL Driver Monitor 表示纹理正在迅速增加。怎么找漏点?

python测试通过ftp发送文件

python - 导入错误 : No module named Scrapy; even if Scrapy was successfully installed

macos - 如何在 Mac 应用程序启动期间将外部框架添加到系统库

python - 向 matplotlib 图形添加标签

python - 从 labelme json 文件创建 tfrecord

python - 如何构建IMS开源语料库工作台和NLTK可读语料库?