ImportError: No module named six


#1

I’ve a simple yaml to build a python2 application, but it always fails to build with the “ImportError: No module named six” error. The project has a requirements.txt which specifies six, but I have also tried specifying it with python-packages and stage-packages in the yaml, but it always fails the same way. Any ideas?

name: offlineimap
version: 'master'
summary: OfflineIMAP
description: |
  Read/sync your IMAP mailboxes

grade: stable
confinement: strict

apps:
  offlineimap:
    command: bin/offlineimap
    plugs:
      - network

parts:
  offlineimap:
    plugin: python
    python-version: python2
    source: https://github.com/OfflineIMAP/offlineimap.git
    build-packages:
      - gcc
      - g++


#2

It looks like the error here is in the pull stage of snapcraft. When snapcraft runs setup.py it ends up wanting to import six (via an import of offlineimap). You’ll want to ensure you have six setup in the Python environment that snapcraft uses to build offlineimap part.


#3

Thanks for the suggestions. I went for this which works, but looks inelegant to me. Any suggestions for improvements?

name: offlineimap
version: 'master'
summary: OfflineIMAP
description: |
  Read/sync your IMAP mailboxes

grade: stable
confinement: strict

apps:
  offlineimap:
    command: bin/offlineimap
    plugs:
      - network

parts:
  setup:
    plugin: python
    python-version: python2
    python-packages: [six]
  offlineimap:
    after: [setup]
    plugin: python
    python-version: python2
    source: https://github.com/OfflineIMAP/offlineimap.git
    build-packages:
      - gcc
      - g++

#4

I think what you have is just fine, I agree it’s not pretty but that’s just the nature of the beast.


#5

Hey @popey, sorry for coming late. I’m happy that @sparkiegeek got here earlier, because nothing I tried worked.

His suggestion looks very good to me, and something new to my list of tips & tricks. :slight_smile:


#6

There is a bug here:

https://bugs.launchpad.net/snapcraft/+bug/1712634

If you want the snapcraft.yaml to be in the same project as the source code, even the separate part to install setup deps will find the setup.py and try to install it.

We need a better story for this case.


#7

First of all - I’m just started snapcraft learning.

I tried to build offlineimap python example from here:
https://docs.snapcraft.io/build-snaps/python

My snapcraft setup is according to this (Build on LXD or Docker) - I’m using LXD:
https://docs.snapcraft.io/build-snaps/build-on-lxd-docker

I’m running snapcraft with the following command line:

$ lxc exec snapcraft – sh -c “cd $(pwd); snapcraft”

I’m also getting ImportError: No module named six`.

Is this because of

  • problem is not fixed yet?
  • my build setup is affecting this?

Any idea how to fix the example?

Just wondering that if there is known issue to build offlineimap why it is still used as python example?


#8

Sorry for the delay. Looks like we need to update the python example. Note that the genuine offlineimap snap is built slightly differently and fixes the ‘six’ issue.

I’ll get the tutorial updated. Thanks.