"pip3 install numpy" fails on brewed Python 3.5

3

我使用安装了Homebrew的Python 3.5的OS X Yosemite系统。

尝试使用pip3 install numpy安装NumPy,结果出现以下错误:

Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/setup.py", line 251, in <module>
        setup_package()
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/setup.py", line 243, in setup_package
        setup(**metadata)
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/numpy/distutils/core.py", line 169, in setup
        return old_setup(**new_attr)
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/numpy/distutils/command/install.py", line 62, in run
        r = self.setuptools_run()
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/numpy/distutils/command/install.py", line 36, in setuptools_run
        return distutils_install.run(self)
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/command/install.py", line 539, in run
        self.run_command('build')
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/numpy/distutils/command/build.py", line 39, in run
        old_build.run(self)
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/numpy/distutils/command/build_src.py", line 153, in run
        self.build_sources()
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/numpy/distutils/command/build_src.py", line 170, in build_sources
        self.build_extension_sources(ext)
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/numpy/distutils/command/build_src.py", line 329, in build_extension_sources
        sources = self.generate_sources(sources, ext)
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-ocs2rs8s/numpy/numpy/distutils/command/build_src.py", line 386, in generate_sources
        source = func(extension, build_dir)
      File "numpy/core/setup.py", line 432, in generate_config_h
        moredefs, ignored = cocache.check_types(config_cmd, ext, build_dir)
      File "numpy/core/setup.py", line 42, in check_types
        out = check_types(*a, **kw)
      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.

尤其是找不到 Python.h 文件,但实际上它在 /usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/include/python3.5m/Python.h 的路径下存在。

我该怎么做?


你有Python开发包吗? - Tim
1
我认为Homebrew不使用单独的开发人员包。brew search python-dev没有任何结果。请参阅此评论:https://dev59.com/y2Ei5IYBdhLWcg3wX7XP#21341666。 - MortenB
1
好链接,谢谢。你可以考虑使用brew安装numpy吗? - Tim
我最终使用了 brew install homebrew/python/numpy。这个方法可行。 - MortenB
3个回答

2

1
这与一个numpy bug有关。这是因为3.4及之前版本拥有wheels(二进制包),而3.5还没有(因为在问题提出时,Python 3.5刚发布)。目前建议的解决方案是 pip3 install git+https://github.com/numpy/numpy.git - user707650
笔误:pip3 install git+https://github.com/numpy/numpy.git(可能需要您先安装Cython)。但是请参见问题本身的OPs评论,以获取另一种解决方案。 - user707650

0
系统错误:无法编译“Python.h”。也许您需要安装python-dev|python-devel。
请尝试安装Python开发库。

错误信息通常针对GNU-Linux。此外,很可能需要安装python3-dev软件包。Numpy试图提供有用的错误信息,但结果更加混乱。 - user707650

0

我有同样的问题。

以下方法对我很有帮助:

使用浏览器下载并安装Python35的miniconda(64位)。请参见:

http://conda.pydata.org/miniconda.html

使下载的脚本可执行。
chmod 777 <scriptname>

并使用适当的权限运行它。

使用以下命令安装numpy

conda install numpy

再次使用适当的权限。

不要总是使用sudo,可以使用sudo xterm并从那里工作。


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