【问题标题】:Can't install numpy with setup.py无法使用 setup.py 安装 numpy
【发布时间】:2013-05-19 22:11:32
【问题描述】:

我使用的是 Python 2.7,我正在尝试使用 NLTK 词性标注器,由于我没有安装 numpy,因此会生成此错误:

> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/nltk/tag/__init__.py", line 99, in pos_tag
    tagger = load(_POS_TAGGER)
  File "/Library/Python/2.7/site-packages/nltk/data.py", line 605, in load
    resource_val = pickle.load(_open(resource_url))
ImportError: No module named numpy.core.multiarray

所以我从here 下载了 numpy 1.7.0,将 cd 放入我的下载文件夹并安装了 python setup.py 并收到此错误:

Running from numpy source directory.
non-existing path in 'numpy/distutils': 'site.cfg'
F2PY Version 2
blas_opt_info:
  FOUND:
    extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
    define_macros = [('NO_ATLAS_INFO', 3)]
    extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers']

lapack_opt_info:
  FOUND:
    extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
    define_macros = [('NO_ATLAS_INFO', 3)]
    extra_compile_args = ['-msse3']

running install
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building py_modules sources
creating build
creating build/src.macosx-10.6-intel-2.7
creating build/src.macosx-10.6-intel-2.7/numpy
creating build/src.macosx-10.6-intel-2.7/numpy/distutils
building library "npymath" sources
customize Gnu95FCompiler
Could not locate executable gfortran
Could not locate executable f95
customize NAGFCompiler
customize AbsoftFCompiler
Could not locate executable f90
Could not locate executable f77
customize IBMFCompiler
Could not locate executable xlf90
Could not locate executable xlf
customize IntelFCompiler
Could not locate executable ifort
Could not locate executable ifc
customize GnuFCompiler
Could not locate executable g77
customize G95FCompiler
Could not locate executable g95
customize PGroupFCompiler
Could not locate executable pgfortran
don't know how to compile Fortran code on platform 'posix'
C compiler: gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3

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 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c'
gcc-4.2: _configtest.c
sh: gcc-4.2: command not found
sh: gcc-4.2: command not found
failure.
removing: _configtest.c _configtest.o
Traceback (most recent call last):
  File "setup.py", line 214, in <module>
    setup_package()
  File "setup.py", line 207, in setup_package
    configuration=configuration )
  File "/Users/mikaschiller/Downloads/numpy-1.7.0/numpy/distutils/core.py", line 186, in setup
    return old_setup(**new_attr)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/Users/mikaschiller/Downloads/numpy-1.7.0/numpy/distutils/command/install.py", line 55, in run
    r = old_install.run(self)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 563, in run
    self.run_command('build')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/Users/mikaschiller/Downloads/numpy-1.7.0/numpy/distutils/command/build.py", line 37, in run
    old_build.run(self)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build.py", line 127, in run
    self.run_command(cmd_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/Users/mikaschiller/Downloads/numpy-1.7.0/numpy/distutils/command/build_src.py", line 152, in run
    self.build_sources()
  File "/Users/mikaschiller/Downloads/numpy-1.7.0/numpy/distutils/command/build_src.py", line 163, in build_sources
    self.build_library_sources(*libname_info)
  File "/Users/mikaschiller/Downloads/numpy-1.7.0/numpy/distutils/command/build_src.py", line 298, in build_library_sources
    sources = self.generate_sources(sources, (lib_name, build_info))
  File "/Users/mikaschiller/Downloads/numpy-1.7.0/numpy/distutils/command/build_src.py", line 385, in generate_sources
    source = func(extension, build_dir)
  File "numpy/core/setup.py", line 648, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
RuntimeError: Broken toolchain: cannot link a simple C program   

然后我尝试使用 sudo pip install -U numpy 安装它并得到相同的“无法链接简单的 C 程序”错误。我无法弄清楚这里发生了什么。 numpy 版本是否与 python 2.7 或 NLTK 不兼容?

【问题讨论】:

    标签: python python-2.7 numpy nltk


    【解决方案1】:

    该模块依赖于一个有效的 C 构建链。这取决于您的系统如何安装它,谷歌会在这种情况下提供帮助。

    你可以看到它正在寻找 gcc:

    sh: gcc-4.2: command not found
    

    在基于 Debian 的 linux 上,您可以安装它和 python 头文件(根据评论编辑):

    sudo apt-get install build-essential python-dev
    

    【讨论】:

    • 别忘了这些系统上还需要python-dev 包。
    • 我在 Mac Lion 10.7.5 和 Xcode 4.6 上,刚刚安装了命令行工具。我在命令行中执行了 gcc -v 以查看是否安装了 gcc 并返回(缩短):使用内置规范。目标:i686-apple-darwin11....线程模型:posix gcc 版本 4.2.1(基于 Apple Inc. build 5658)(LLVM build 2336.11.00)。所以 gcc 显然已安装。我在 numpy 上再次尝试 setup.py install 并得到相同的“Broken toolchain ...”错误。这不是适合狮子的 gcc 版本吗?
    • scipy.org/Installing_SciPy/…export CC=gcc; export CXX=g++; export FFLAGS=ff2c试试这个
    【解决方案2】:

    我遇到了同样的错误并通过更新 pip 修复了它。

    pip install --upgrade pip
    

    希望对你有帮助。

    【讨论】:

    • 你需要加油!
    【解决方案3】:

    最近我一直看到这个:

    clang:错误:未知参数:'-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

    查看此处修复:

    clang error: unknown argument: '-mno-fused-madd' (python package installation failure)

    【讨论】:

      【解决方案4】:

      你需要安装gcc

      在 CentOS 上:

      sudo yum install gcc
      

      如果您看到以下错误,请尝试重新安装numpy

      Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-root/numpy
      

      运行:

      sudo yum install python-devel
      

      【讨论】:

        【解决方案5】:

        也许不是你需要的,但如果你在安装 numpy 时遇到问题,我推荐“Pyzo”。它是一个 python 发行版,附带一组非常有趣的包,其中包括 numpy。 www.pyzo.org

        【讨论】:

          猜你喜欢
          • 2016-07-17
          • 1970-01-01
          • 1970-01-01
          • 2013-11-24
          • 2021-05-20
          • 1970-01-01
          • 2020-02-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多