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