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

'importlib._bootstrap' has no attribute 'SourceLoader'

我正在尝试使用 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'

我正在使用:

我在 Manjaro (Linux)。我不知道问题出在哪里。你能帮帮我吗?

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

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 问题页面中提交错误。

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

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

➜  ~ pip install --upgrade pip
➜  ~ pip install --upgrade virtualenvwrapper
➜  ~ mkvirtualenv -p /usr/local/bin/python3 test_env

我通过 运行 解决了这个问题:

pip3 uninstall setuptools
pip3 install setuptools

运行 这个命令,它会解决你的问题

python3 -m ensurepip --upgrade