When trying to snap a project, we got back this error from snapcraft:
Traceback (most recent call last):
File "/usr/bin/snapcraft", line 31, in <module>
snapcraft.main.main()
File "/usr/lib/python3/dist-packages/snapcraft/main.py", line 226, in main
return run(args, project_options)
File "/usr/lib/python3/dist-packages/snapcraft/main.py", line 282, in run
lifecycle.snap(project_options, args['<directory>'], args['--output'])
File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 289, in snap
snap = execute('prime', project_options)
File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 103, in execute
_Executor(config, project_options).run(step, part_names)
File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 161, in run
self._run_step(step, part, part_names)
File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 197, in _run_step
getattr(part, step)()
File "/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler.py", line 383, in prime
dependencies = _find_dependencies(self.snapdir, snap_files)
File "/usr/lib/python3/dist-packages/snapcraft/internal/pluginhandler.py", line 723, in _find_dependencies
ms = magic.open(magic.NONE)
AttributeError: module 'magic' has no attribute 'open'
What does it mean, and how can it be solved?
There are two python modules named magic, with different APIs.
The one that snapcraft requires is packaged as a deb named python3-magic. This one corresponds to the module file-magic in pypi: https://pypi.python.org/pypi/file-magic
The other one is just called magic in pypi: https://pypi.python.org/pypi/magic
So if you do:
You will get the wrong one, and it will be installed to a path that takes precedence over the python3-magic deb installed with apt. That's what causes the error.
To check if you have the other magic module installed from pip:
And to remove it and fix snapcraft:
as of time of writing the solution is: