如何修复“ ImportError:无法导入名称'printmsg'”

时间:2019-02-12 08:33:48

标签: python python-3.x

使用buildozer构建apk时,我得到的错误归结为调用automake w / o参数的错误:

$ automake
Traceback (most recent call last):
  File "/usr/local/bin/automake", line 11, in <module>
    load_entry_point('automake==0.1.3', 'console_scripts', 'automake')()
  File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 487, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 2728, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 2346, in load
    return self.resolve()
  File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 2352, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python3.5/dist-packages/automake/cli.py", line 6, in <module>
    from utils import printmsg
ImportError: cannot import name 'printmsg'

我已经重新安装了automake。以下是相关版本:

$ sudo pip install automake
Requirement already satisfied: automake in /usr/local/lib/python3.5/dist-packages (0.1.3)
Requirement already satisfied: click in /usr/local/lib/python3.5/dist-packages (from automake) (7.0)
Requirement already satisfied: watchdog in /usr/local/lib/python3.5/dist-packages (from automake) (0.9.0)
Requirement already satisfied: PyYAML>=3.10 in /usr/local/lib/python3.5/dist-packages (from watchdog->automake) (3.13)
Requirement already satisfied: argh>=0.24.1 in /usr/local/lib/python3.5/dist-packages (from watchdog->automake) (0.26.2)
Requirement already satisfied: pathtools>=0.1.1 in /usr/local/lib/python3.5/dist-packages (from watchdog->automake) (0.1.2)

1 个答案:

答案 0 :(得分:2)

您正在使用的项目的0.1.3版本已被破坏。由于它的cli模块假定automake包的目录本身位于Python路径上,因此automake.utils可以作为utils导入。 >

在您的系统上,该ImportError行没有抛出from utils import printmsg,而是在其他地方找到了一个不同的顶层utils模块。不论找到什么内容或在哪里,都无关紧要,因为它不是正确的模块。

作者做了commit a partial fix for this problem,但这样做时显然错过了automake/cli.py文件。您可以手动修复它(用from utils中的from .utils替换/usr/local/lib/python3.5/dist-packages/automake/cli.py)。

如果您正在寻找GNU automake tool,则不需要此Python项目。鉴于您正在构建Kivy APK,几乎可以肯定正在寻找GNU项目,而不是这个项目。

提交issue with the automake Python project后,作者同意他们选择的名字可能会引起冲突,因此将其从PyPI中删除。