Snapcraft Python2 使用 python-dev 构建 numpy

Snapcraft Python2 使用 python-dev 构建 numpy

刚刚开始接触 snappy。我正在尝试将一个 python 项目移植到一个 snappy 应用程序。python 代码依赖于 numpy 1.5.1,而 numpy 1.5.1 依赖于已安装的 python-dev。

我的 snapcraft 零件部分如下所示:

parts:
    mypythonapp:
        plugin: python2
        source: https://github.com/me/mypythonapp.git
        source-type: git
        build-packages:
            - gcc
            - gfortran
            - libblas-dev
            - liblapack-dev
            - cython
            - python-dev
        python-packages:
            - numpy==1.5.1

当我snapcraft pull尝试构建 numpy 时,出现以下错误:

    x86_64-linux-gnu-gcc: build/src.linux-x86_64-2.7/numpy/core/src/npymath/ieee754.c
        In file included from numpy/core/src/npymath/ieee754.c.src:7:0:
        numpy/core/src/npymath/npy_math_common.h:4:20: fatal error: Python.h: No such file or directory
        compilation terminated.
        In file included from numpy/core/src/npymath/ieee754.c.src:7:0:
        numpy/core/src/npymath/npy_math_common.h:4:20: fatal error: Python.h: No such file or directory
        compilation terminated.

error: Command "x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -I/home/me/Code/mypythonapp-snap/parts/mypythonapp/install/usr/include -I/home/me/Code/mypythonapp-snap/parts/mypythonapp/install/usr/include -I/home/me/Code/mypythonapp-snap/parts/mypythonapp/install/usr/include/x86_64-linux-gnu -I/home/me/Code/mypythonapp-snap/parts/mypythonapp/install/usr/include -I/home/me/Code/mypythonapp-snap/parts/mypythonapp/install/usr/include -I/home/me/Code/mypythonapp-snap/parts/mypythonapp/install/usr/include/x86_64-linux-gnu -fPIC -Inumpy/core/include -Ibuild/src.linux-x86_64-2.7/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/include -Ibuild/src.linux-x86_64-2.7/numpy/core/src/multiarray -Ibuild/src.linux-x86_64-2.7/numpy/core/src/umath -c build/src.linux-x86_64-2.7/numpy/core/src/npymath/ieee754.c -o build/temp.linux-x86_64-2.7/build/src.linux-x86_64-2.7/numpy/core/src/npymath/ieee754.o"

我可以找到Python.h位于./parts/mypythonapp/install/usr/include/python2.7/Python.h。当我查看所有包含的路径时,我注意到它usr/include/python2.7不在那里。

有没有办法让我包含类似于 autotools 插件 configflags 的路径?还是我遗漏了一些简单的东西?

编辑env:我通过修改位于的 python2 插件中的函数 取得了一些进展/usr/lib/python3/dist-packages/snapcraft/plugins/python2.py

原始函数如下所示:

  def env(self, root):
    # This is until we figure out how to get pip to download only
    # and then build in the build step or split out pulling
    # stage-packages in an internal private step.
    env = [
        'CPPFLAGS="-I{} $CPPFLAGS"'.format(os.path.join(
            root, 'usr', 'include')),
        'CFLAGS="-I{} $CFLAGS"'.format(os.path.join(
            root, 'usr', 'include')),
    ]

我将其修改如下:

def env(self, root):
    # This is until we figure out how to get pip to download only
    # and then build in the build step or split out pulling
    # stage-packages in an internal private step.
    env = [
        'CPPFLAGS="-I{} $CPPFLAGS"'.format(os.path.join(
            root, 'usr', 'include')),
        'CFLAGS="-I{} $CFLAGS"'.format(os.path.join(
            root, 'usr', 'include')),
        'CPPFLAGS="-I{} $CPPFLAGS"'.format(os.path.join(
            root, 'usr', 'include', 'python2.7')),
        'CFLAGS="-I{} $CFLAGS"'.format(os.path.join(
            root, 'usr', 'include' 'python2.7')),
    ]

现在它捡起了Python.h,但它找不到scalartypes.c

x86_64-linux-gnu-gcc: numpy/core/src/multiarray/multiarraymodule_onefile.c
    numpy/core/src/multiarray/multiarraymodule_onefile.c:10:25: fatal error: scalartypes.c: No such file or directory
    compilation terminated.
    numpy/core/src/multiarray/multiarraymodule_onefile.c:10:25: fatal error: scalartypes.c: No such file or directory
    compilation terminated.

答案1

你所做的事情似乎是错误的,这些会引起冲突:

  • plugin: python2期望setup.py
  • python-packages: - numpy==1.5.1包含numpypython 包作为依赖项,为什么你说构建它。
  • build-packages: - gcc - gfortran - libblas-dev - liblapack-dev - cython - python-dev添加了所有这些 C/CPP 工具和库,就像要编译的可能是一个make,,autotools..项目

问题缺少原始代码或可供查看和重现的链接。不过,我建议:

  • 通过检查源/文档来拆分Parts:并设置每个所需的。plugin
  • 使用以下方式对构建过程进行排序:after
  • 是否真的需要构建依赖特定版本或从存储库中预构建的包就足够了?请参阅stage-snaps& stage-packages

相关内容