在尝试捕捉项目时,我们从 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'
这是什么意思,如何解决?
有两个名为 magic 的 Python 模块,具有不同的 API。
snapcraft 需要的是打包为一个名为 python3-magic 的 deb。这个对应pypi中的模块file-magic:https ://pypi.python.org/pypi/file-magic
另一个在 pypi 中被称为魔法:https ://pypi.python.org/pypi/magic
所以如果你这样做:
你会得到错误的,它将被安装到一个优先于使用 apt 安装的 python3-magic deb 的路径。这就是导致错误的原因。
要检查您是否从 pip 安装了其他魔法模块:
并删除它并修复 snapcraft:
截至撰写本文时,解决方案是: