python - 在 Ubuntu 上通过 virtualenv 中的设置工具安装 Numpy 时出错

标签 python ubuntu numpy virtualenv setuptools

我在使用安装工具在 virtualenv 中安装 numpy 时遇到问题。我将 setup() 与通过 install_requires 传入的依赖项列表一起使用。这些依赖项之一是 numpy。我收到一条错误消息,提示找不到 Python.h。但是安装了 python-dev 包。运行:

locate Python.h

返回

/usr/include/python2.7/Python.h

如果我使用pip,我可以成功安装numpy。但是我想要的是在我通过以下方式安装自己的 python 模块时安装 numpy:

python setup.py install

这是错误。安装 Fortran 编译器会消除 Fortran 错误,但仍然会因缺少 Python.h 文件而崩溃。

Searching for numpy==1.8.0
Reading https://pypi.python.org/simple/numpy/
Best match: numpy 1.8.0
Downloading https://pypi.python.org/packages/source/n/numpy/numpy-1.8.0.zip#md5=6c918bb91c0cfa055b16b13850cfcd6e
Processing numpy-1.8.0.zip
Writing /tmp/easy_install-lSyucn/numpy-1.8.0/setup.cfg
Running numpy-1.8.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-lSyucn/numpy-1.8.0/egg-dist-tmp-8m2hid
Running from numpy source directory.
Warning: distutils distribution has been initialized, it may be too late to add a subpackage commandWarning: distutils distribution has been initialized, it may be too late to add a subpackage fcompilernon-existing path in 'numpy/distutils': 'site.cfg'
Warning: distutils distribution has been initialized, it may be too late to add a subpackage distutilsWarning: distutils distribution has been initialized, it may be too late to add a subpackage testingWarning: distutils distribution has been initialized, it may be too late to add a subpackage f2pyWarning: distutils distribution has been initialized, it may be too late to add an extension _dummyWarning: distutils distribution has been initialized, it may be too late to add a library npysortWarning: distutils distribution has been initialized, it may be too late to add an extension multiarrayWarning: distutils distribution has been initialized, it may be too late to add an extension umathWarning: distutils distribution has been initialized, it may be too late to add an extension scalarmath/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/system_info.py:1522: UserWarning: 
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/system_info.py:1531: UserWarning: 
    Blas (http://www.netlib.org/blas/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [blas]) or by setting
    the BLAS environment variable.
  warnings.warn(BlasNotFoundError.__doc__)
/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/system_info.py:1534: UserWarning: 
    Blas (http://www.netlib.org/blas/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [blas_src]) or by setting
    the BLAS_SRC environment variable.
  warnings.warn(BlasSrcNotFoundError.__doc__)
Warning: distutils distribution has been initialized, it may be too late to add an extension _dotblasWarning: distutils distribution has been initialized, it may be too late to add an extension umath_testsWarning: distutils distribution has been initialized, it may be too late to add an extension test_rationalWarning: distutils distribution has been initialized, it may be too late to add an extension struct_ufunc_testWarning: distutils distribution has been initialized, it may be too late to add an extension multiarray_testsWarning: distutils distribution has been initialized, it may be too late to add an extension operand_flag_testsWarning: distutils distribution has been initialized, it may be too late to add a subpackage coreWarning: distutils distribution has been initialized, it may be too late to add an extension _compiled_basenon-existing path in 'numpy/lib': 'benchmarks'
Warning: distutils distribution has been initialized, it may be too late to add a subpackage libWarning: distutils distribution has been initialized, it may be too late to add a subpackage oldnumericWarning: distutils distribution has been initialized, it may be too late to add an extension _capiWarning: distutils distribution has been initialized, it may be too late to add a subpackage numarrayWarning: distutils distribution has been initialized, it may be too late to add an extension fftpack_liteWarning: distutils distribution has been initialized, it may be too late to add a subpackage fft/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/system_info.py:1428: UserWarning: 
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  warnings.warn(AtlasNotFoundError.__doc__)
/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/system_info.py:1439: UserWarning: 
    Lapack (http://www.netlib.org/lapack/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [lapack]) or by setting
    the LAPACK environment variable.
  warnings.warn(LapackNotFoundError.__doc__)
/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/system_info.py:1442: UserWarning: 
    Lapack (http://www.netlib.org/lapack/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [lapack_src]) or by setting
    the LAPACK_SRC environment variable.
  warnings.warn(LapackSrcNotFoundError.__doc__)
Warning: distutils distribution has been initialized, it may be too late to add an extension lapack_liteWarning: distutils distribution has been initialized, it may be too late to add an extension _umath_linalgWarning: distutils distribution has been initialized, it may be too late to add a subpackage linalgWarning: distutils distribution has been initialized, it may be too late to add an extension mtrandWarning: distutils distribution has been initialized, it may be too late to add a subpackage randomWarning: distutils distribution has been initialized, it may be too late to add a subpackage maWarning: distutils distribution has been initialized, it may be too late to add a subpackage matrixlibWarning: distutils distribution has been initialized, it may be too late to add a subpackage compatWarning: distutils distribution has been initialized, it may be too late to add a subpackage polynomialWarning: distutils distribution has been initialized, it may be too late to add a subpackage docWarning: distutils distribution has been initialized, it may be too late to add a subpackage numpyCould not locate executable gfortran
Could not locate executable f95
Could not locate executable ifort
Could not locate executable ifc
Could not locate executable lf95
Could not locate executable pgfortran
Could not locate executable f90
Could not locate executable f77
Could not locate executable fort
Could not locate executable efort
Could not locate executable efc
Could not locate executable g77
Could not locate executable g95
Could not locate executable pathf95
don't know how to compile Fortran code on platform 'posix'
_configtest.c:1:5: warning: conflicting types for built-in function ‘exp’ [enabled by default]
_configtest.o: In function `main':
/tmp/easy_install-lSyucn/numpy-1.8.0/_configtest.c:6: undefined reference to `exp'
collect2: error: ld returned 1 exit status
_configtest.o: In function `main':
/tmp/easy_install-lSyucn/numpy-1.8.0/_configtest.c:6: undefined reference to `exp'
collect2: error: ld returned 1 exit status
_configtest.c:1:5: warning: conflicting types for built-in function ‘exp’ [enabled by default]
_configtest.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.
_configtest.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.
Traceback (most recent call last):
  File "setup.py", line 178, in <module>
    install_app()
  File "setup.py", line 119, in install_app
    entry_points=ENTRY_POINTS
  File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "build/bdist.linux-x86_64/egg/setuptools/command/develop.py", line 27, in run
  File "build/bdist.linux-x86_64/egg/setuptools/command/develop.py", line 129, in install_for_development
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 687, in process_distribution
  File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 568, in resolve
  File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 806, in best_match
  File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 818, in obtain
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 609, in easy_install
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 639, in install_item
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 825, in install_eggs
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1031, in build_and_install
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1016, in run_setup
  File "build/bdist.linux-x86_64/egg/setuptools/sandbox.py", line 69, in run_setup
  File "build/bdist.linux-x86_64/egg/setuptools/sandbox.py", line 120, in run
  File "build/bdist.linux-x86_64/egg/setuptools/sandbox.py", line 71, in <lambda>
  File "setup.py", line 192, in <module>

  File "setup.py", line 185, in setup_package

  File "/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/core.py", line 169, in setup
  File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "build/bdist.linux-x86_64/egg/setuptools/command/bdist_egg.py", line 177, in run
  File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/command/egg_info.py", line 10, in run
  File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/command/build_src.py", line 153, in run
  File "/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/command/build_src.py", line 170, in build_sources
  File "/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/command/build_src.py", line 329, in build_extension_sources
  File "/tmp/easy_install-lSyucn/numpy-1.8.0/numpy/distutils/command/build_src.py", line 386, in generate_sources
  File "numpy/core/setup.py", line 427, in generate_config_h

  File "numpy/core/setup.py", line 42, in check_types

  File "numpy/core/setup.py", line 288, in check_types

SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.

这些是我正在使用的版本:

Ubuntu: 12.10
Setuptools: 1.4.2
Numpy: 1.8.0

最佳答案

您似乎没有安装 Fortran 编译器。试试 apt-get install gfortran

关于python - 在 Ubuntu 上通过 virtualenv 中的设置工具安装 Numpy 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20356725/

相关文章:

node.js - 当 Amazon EC2 上的 CPU 使用率达到 100% 并且服务器停止时如何重新启动我的 Node js 应用程序

Python 如何在 numpy 数组中查找第一个重复项

python - Pycharm/Windows 10 键盘快捷键冲突

python - 定义一个带有类型的列表

python - 在循环中调用 repaint() 时,pyqt5 中的 QPainter 不会绘制任何内容。我该如何解决?

c - struct 没有从 c 上的函数正确返回

ubuntu - 带有 ubuntu 的树莓派 POE-FAN 帽子

python - 编辑二维数组中元素的简单方法 Python :

python - python中的3d sobel算法?

Python bool 比较逻辑错误