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

时间:2015-09-17 16:38:27

标签: 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的目录中。所以我现在很困惑。

更新18月9日,确切的错误消息: 最初它试图建立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

然后安装报告了同样的错误。

2 个答案:

答案 0 :(得分:1)

根据this page,此问题已在numpy 1.9.3版中修复。试试

pip3 install numpy==1.9.3

答案 1 :(得分:0)

现在默认情况下,OSX的Python标头有些混乱/未安装。你可以运行:

xcode-select --install然后安装命令行工具,它应该可以工作。