Gfortran 无法编译 NumPy

Gfortran can't compile NumPy

我正在开发一个基于 Raspberry 的项目,该项目需要 SciPy、NumPy 和 scikit-learn。我们需要将我们的虚拟环境打包成 .deb 文件以便分发。为此,我们使用 dh_virtualenv,到目前为止效果很好。

当我刚刚在 venv 上安装我们的需求时,像这样:

myvenv/bin/pip install numpy
myvenv/bin/pip install scipy
myvenv/bin/pip install sklearn

依赖项安装得很好,尽管它们需要很长时间才能完成。

当我们尝试按照以下步骤制作包时,问题就来了:

mkdir myvenv-0.1
cd myvenv-0.1
dh_make --createorig
nano ./debian/rules

然后我在编辑器中找到 "dh $@" 部分并将其替换为

%:
    dh $@ --with python-virtualenv --python /path/to/myvenv/bin/python

然后我编辑 debian/control:

nano ./debian/control

并这样填写:

Source: myvenv
Maintainer: My Name <mymail@mymail.com>
Build-Depends: debhelper (>= 9)
Standards-Version: 3.9.5
Homepage: <insert the upstream URL, if relevant>

Package: myvenv
Version: 0.1-1
Architecture: armhf
Pre-Depends: dpkg (>= 1.16.1), python2.7 | python2.6
Section: python
Priority: extra
Description: My Description

那我冻结我的需求:

/path/to/myvenv/bin/pip freeze > requirements.txt

纳米进入其中:

nano requirements.txt

然后我寻找myvenv需求行并将其删除,否则venv需要自己,这会在后面破坏整个过程(我太了解了。)

此时我为 myvenv 包生成了一个 setup.py 文件,它必须执行一个伪造的单元测试命令,因为 dh_virtualenv 默认尝试 运行 单元测试并且禁用它们的标志不起作用。这是文件:

from distutils.core import setup
from distutils.cmd import Command


class TestCommand(Command):
  user_options=[]
  description = ''
  def initialize_options(self):
    pass

  def finalize_options(self):
    pass

  def run(self):
    self.announce('test')


setup(
      cmdclass={
             'test': TestCommand
      },
      name='myvenv',
      version='0.1',
      description='desc')

然后导出需要安装myvenv的路径:

export DH_VIRTUALENV_INSTALL_ROOT=/path/

最后,我可以构建包,但我需要先提交,所以我这样做了

dpkg-source --commit

我随便给补丁起个名字然后按回车键,然后我:

dpkg-buildpackage -us -uc

这个程序一直运行良好,直到现在我有一个 python class 可以自动执行此操作。

这些库也可以很好地安装在 venv 本身上。

但是,无论出于何种原因,打包 virtualenv 只会导致 gfortran 崩溃。

错误回溯很大,基本上是这样结束的:

  File "/path/to/myvenv-0.1/debian/myvenv/path/to/myvenv/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 1066, in run_setup

    raise DistutilsError("Setup script exited with %s" % (v.args[0],))

distutils.errors.DistutilsError: Setup script exited with error: Command "/usr/bin/gfortran -Wall -g -Wl,-z,relro build/temp.linux-armv7l-3.4/numpy/linalg/lapack_litemodule.o build/temp.linux-armv7l-3.4/numpy/linalg/lapack_lite/python_xerbla.o -L/usr/lib/atlas-base/atlas -L/usr/lib/atlas-base -L/usr/lib/gcc/arm-linux-gnueabihf/4.9 -L/usr/lib/gcc/arm-linux-gnueabihf/4.9 -Lbuild/temp.linux-armv7l-3.4 -llapack -lf77blas -lcblas -latlas -lf77blas -lcblas -lgfortran -o build/lib.linux-armv7l-3.4/numpy/linalg/lapack_lite.cpython-34m.so" failed with exit status 1



----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-ouvtjhcw/scipy
Storing debug log for failure in /home/admin/.pip/pip.log
Traceback (most recent call last):
  File "/usr/bin/dh_virtualenv", line 85, in <module>
    sys.exit(main() or 0)
  File "/usr/bin/dh_virtualenv", line 67, in main
    deploy.install_dependencies()
  File "/usr/lib/python2.7/dist-packages/dh_virtualenv/deployment.py", line 112, in install_dependencies
    subprocess.check_call(self.pip('-r', requirements_path))
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['debian/myvenv/path/to/myvenv/bin/python', 'debian/myvenv/path/to/myvenv/bin/pip', 'install', '--log=/tmp/tmpRjP02B', '-r', './requirements.txt']' returned non-zero exit status 1
debian/rules:22: recipe for target 'binary' failed
make: *** [binary] Error 1
dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2

再往上说它正在安装 lapack_lite。抱歉,我不得不重新启动计算机,并且需要很长时间才能再次 运行。我只保留了最后一部分以供进一步网络搜索(到目前为止还没有找到任何结果。)

平台是 Raspbian。另外 Python 是版本 3.4.4。 Pip 的版本是 1.5.6

更新

在 45 分钟的纯粹幸福之后,我有了另一个日志。我有完整的东西。它太大了,我不得不 put it on pastebin,事实上。

TL;DR: 使用 piwheels。

为了解决这个问题我吃了不少苦头,基本上我已经放弃了,直到我找到了 piwheels。

它是相当新的,也许您会得到 scipy 1.0.0 而不是 1.0.1,但实际上,谁在乎呢。 它还会大大减少打包 venv 所需的时间。

只需覆盖 debian/rules 文件中的 dh_virtualenv,如下所示:

[...]
override_dh_virtualenv:
    dh_virtualenv --python /path/to/myvenv/bin/python -v --extra-index-url https://www.piwheels.org/simple
%:
[...]