can't build python part with C modules

Bug #1802345 reported by Alberto Donato
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Snapcraft
New
Undecided
Unassigned

Bug Description

Building python packages that have C modules fails with snapcraft as C headers are not found.

This is a sample snap that fails building on Bionic:

name: test
version: '1.0'
summary: test
description: test
grade: stable
confinement: strict
base: core18

apps:
  uwsgi:
    command: uwsgi

parts:
  uwsgi:
    plugin: python
    source: .
    python-packages:
      - uWSGI
    build-packages:
      - python3-dev
    stage-packages:
      - libpython3.6

exporting C_INCLUDE_PATH=/usr/include/python3.6 makes it work.

Tested with both stable (2.43.1) and candidate (3.0) snaps.

Also, removing the core18 base and using libpython3.5 when building on xenial shows the same issue

Alberto Donato (ack)
description: updated
description: updated
Alberto Donato (ack)
description: updated
Revision history for this message
Alberto Donato (ack) wrote :

This is a bigger issue when building with VMs in snapcraft 3, as there's no way to export C_INCLUDE_PATH.

FWIW I also tried

override-build: |
   export C_INCLUDE_PATH=/usr/include/python3.6
   snapcraftctl build

but that didn't work for me either

Revision history for this message
林博仁(Buo-ren, Lin) (buo-ren-lin) wrote :

> This is a bigger issue when building with VMs in snapcraft 3, as there's no way to export C_INCLUDE_PATH.

You can use the `build-environment` key, refer https://github.com/snapcore/snapcraft/pull/2322 for more info.

For legacy Snapcraft syntax you have to override the build step and build the part manually, or [write a local plugin](https://forum.snapcraft.io/t/writing-local-plugins/5125) to replace/complement [the `python` plugin](https://github.com/snapcore/snapcraft/blob/master/snapcraft/plugins/python.py).

Revision history for this message
林博仁(Buo-ren, Lin) (buo-ren-lin) wrote :

Here's the part recipe that fixes the problem:

```
parts:
  uwsgi:
    plugin: python
    source: .
    python-packages:
      - uWSGI
    build-packages:
      - python3-dev
    build-environment:
      - C_INCLUDE_PATH: /usr/include/python3.6
    stage-packages:
      - libpython3.6
```

I noticed that "/usr/include/*/Python.h" isn't in any of the default GCC preprocessor search paths though, is the regular non-snap build really can't reproduce this issue?

Revision history for this message
Alberto Donato (ack) wrote :

Thanks, that's much nicer that having to export it outside of snapcraft!

Still, I think this bug is valid as snapcraft should pass that export itself in the python plugin, as it knows the python version that's being used.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.