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

Ber*_*uan 5 python macos numpy

我的操作系统是OSX 10.10.4,我有python2.7.10和python3.5,并尝试为这两个版本的python安装numpy,scipy和matplotlib.

在python2中它运行良好,但对于python3,我尝试使用命令安装numpy

pip3 install numpy
Run Code Online (Sandbox Code Playgroud)

然后事实证明安装终止,因为它找不到文件Python.h但实际上文件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
Run Code Online (Sandbox Code Playgroud)

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

Eug*_*e K 0

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

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