使用 python-dev 构建 numpy 的 Snapcraft Python2

gbl*_*rd4 5 python numpy snap

刚开始用活泼的方式弄脏我的手。我正在尝试将一个 python 项目移植到一个活泼的应用程序。python 代码依赖于 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
Run Code Online (Sandbox Code Playgroud)

当我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"
Run Code Online (Sandbox Code Playgroud)

我可以找到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')),
    ]
Run Code Online (Sandbox Code Playgroud)

我修改它看起来像:

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')),
    ]
Run Code Online (Sandbox Code Playgroud)

现在它拿起了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.
Run Code Online (Sandbox Code Playgroud)

use*_*.dz 0

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

  • 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-snapsstage-packages