'importlib._bootstrap'没有属性'SourceLoader'

时间:2015-10-27 10:29:27

标签: python cx-freeze esky

我正在尝试用cx_freeze和esky构建一个应用程序。它之前正在工作(好吧,也许几个月前。从那时起,python 3.5就出来了。)

我有以下例外:

File "/usr/lib/python3.5/site-packages/esky/util.py", line 578, in compile_to_bytecode
    loader = importlib._bootstrap.SourceLoader()    
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceLoader'

我正在使用:

  • Python 3.5.0
  • 来自pypi的Esky 0.9.9(最新)
  • cx_freeze 4.3.4-2

我在Manjaro(Linux)上。我无法弄清楚问题的来源。你能帮我一把吗?

4 个答案:

答案 0 :(得分:6)

我今天遇到了同样的问题。

在终端中运行以下命令解决了我的问题。

[(a1,E1),(a2,E2)]

答案 1 :(得分:2)

mmm可能存在查看源代码的错误:

if sys.version_info[:2] < (3, 1):
    bytecode = imp.get_magic() + struct.pack("<i", 0)
    bytecode += marshal.dumps(compile(source_code, compile_filename, "exec"))
elif sys.version_info[:2] < (3, 4):
    bytecode = imp.get_magic() + struct.pack("<ii", 0, 0)
    bytecode += marshal.dumps(compile(source_code, compile_filename, "exec"))
else:
    loader = importlib._bootstrap.SourceLoader()    
    code = loader.source_to_code(source_code, '<string>')
    bytecode = importlib._bootstrap._code_to_bytecode(code, mtime=0, source_size=0)

您可以尝试用以下代码替换该行:

loader = importlib._bootstrap_external.SourceLoader()

如果可以,请尝试使用小于3.5的版本,并在其github问题页面中提交错误。

答案 2 :(得分:2)

我能够通过运行以下内容解决此问题:

pip3 uninstall setuptools
pip3 install setuptools

答案 3 :(得分:1)

运行此命令,它将解决您的问题

python3 -m ensurepip --upgrade