Suddenly unable to build Python 3 snaps - ImportError: No module named 'six'

Until recently, I had no problem building my snaps that use Python 3. I’ve tried with a brand new snapcraft.yaml and on a different server, but I still get the same build error.

This is my snapcraft.yaml:

name: my-snap-name # you probably want to 'snapcraft register <name>'
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

parts:
  my-part:
    # See 'snapcraft plugins'
    plugin: python
    python-packages:
      - pillow

I am only trying to install the one package (just to test the problem) and I get the following:

  ImportError: No module named 'six'
  
  ----------------------------------------
  Failed building wheel for olefile
  Running setup.py clean for olefile
Failed to build olefile

I have tried adding six to python-packages, but it still results in the same problem. Any ideas on how to resolve this?

1 Like

Same problem for us on fully updated 16.04. last successful run of our CI pipeline was about 12h ago

Same here for python-2 based snaps building.

 import six
 ImportError: No module named six
 ----------------------------------------
 Failed building wheel for docker-compose
 Running setup.py clean for docker-compose
 Running setup.py bdist_wheel for docopt ... error

I’m not sure that this is caused by snapcraft, I see the same errors when downgrading to snapcraft==2.27.1 and trying again.

I managed to make it work by adding six to the packages installed by _install_pip. You can use this patch to make sure six is installed at bootstrapping:

--- /usr/lib/python3/dist-packages/snapcraft/plugins/python.py	2017-06-01 04:50:52.732859841 +0000
+++ python.py	2017-06-01 04:56:33.267038528 +0000
@@ -219,7 +219,7 @@
         if not self._get_python_command().startswith(self.project.stage_dir):
             env['PYTHONHOME'] = '/usr'
 
-        args = ['pip', 'setuptools', 'wheel']
+        args = ['pip', 'setuptools', 'wheel', 'six']
 
         pip_command = [self._get_python_command(), '-m', 'pip']

I had a quick testing on snapcraft=2.28, which worked fine before with my snap building. It failed to build too now. After applying the above patch, I can manage to get through it.
Thanks.

Patching the plugin to always install six does not seem to be the right thing to do. Alternatively I would either get the upstream setup properly again or ultimately add six to python-packages. I cannot recall off the top of my head if ordering was important here, but if it is, make sure it is first on the python-packages list.

Getting this in the Nextcloud snap as well. And I actually see lib/python2.7/site-packages/six.py. This is in a virtualenv, completely outside of snapcraft.

1 Like

Sounds like a setuptools change, according to this and this.

1 Like

@sergiusens assuming I understand what’s happening here, it seems the fix is indeed to install six as in the patch above. To quote this comment:

You can’t install from sdist without having installed setuptools dependencies first, but if you ensure that the dependencies are installed, then you can install from sdist. Eventually, PEP 518 support should come to pip at which point pip will be able to install setuptools from sdist without prerequisites. It is a significant breaking change, and I appreciate the efforts some of you have to expend to help make this transition. I’ve done everything I can to limit the impact, and if you can think of something more that can be done, please do share.

Breakage aside, the patch seems acceptable because we always include setuptools.

We’re rolling out a fix as fast as we can folks, hang in there. Relevant bug: #1694945. Note that there is no known workaround: python-packages aren’t installed soon enough for six to be added there and succeed.

We (thankfully) got beat to the punch: setuptools realized their error and released v36.0.1, which is now in pypi. You should all be fixed now with no changes needed. Please let us know if that is not the case.

4 Likes

Thanks for looking into this so quickly. The setuptools update did fix the problem.