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

JPF*_*oia 9 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'
Run Code Online (Sandbox Code Playgroud)

我正在使用:

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

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

小智 7

我能够通过运行来解决这个问题:

pip3 uninstall setuptools
pip3 install setuptools
Run Code Online (Sandbox Code Playgroud)


小智 6

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

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

?  ~ pip install --upgrade pip
?  ~ pip install --upgrade virtualenvwrapper
?  ~ mkvirtualenv -p /usr/local/bin/python3 test_env
Run Code Online (Sandbox Code Playgroud)


lap*_*ira 2

嗯,查看源代码可能存在错误:

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)
Run Code Online (Sandbox Code Playgroud)

您可以尝试将该行替换为:

loader = importlib._bootstrap_external.SourceLoader()

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