10

I'm trying to build an app with cx_freeze and esky. It was working before (ok, maybe some months ago. Since then, python 3.5 went out).

I have the following exception:

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'

I'm using:

  • Python 3.5.0
  • Esky 0.9.9 (latest) from pypi
  • cx_freeze 4.3.4-2

And I'm on Manjaro (Linux). I can not figure out where the problem comes from. Could you give me a hand please ?

JPFrancoia
  • 4,866
  • 10
  • 43
  • 73

4 Answers4

9

I was able to fix the issue by running:

pip3 uninstall setuptools
pip3 install setuptools
Shingboo
  • 91
  • 1
  • 3
6

I ran into this same problem today.

Running the following commands in terminal resolved my problem.

➜  ~ pip install --upgrade pip
➜  ~ pip install --upgrade virtualenvwrapper
➜  ~ mkvirtualenv -p /usr/local/bin/python3 test_env
Justin Beall
  • 71
  • 1
  • 5
2

mmm there might be a bug there looking at the source code:

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)

Can you try to replace that line with:

loader = importlib._bootstrap_external.SourceLoader()

If that works then try using a lesser version than 3.5 and submit a bug in their github issue page.

lapinkoira
  • 8,320
  • 9
  • 51
  • 94
  • Hum, it still doesn't work, but for another reason: ```AttributeError: module 'importlib._bootstrap' has no attribute '_code_to_bytecode'``` at line 580 of the same file. A bit better, we moved two lines ahead :) – JPFrancoia Oct 27 '15 at 10:56
  • 1
    Yes, because that line also have to be changed to'bytecode = importlib._bootstrap_external._code_to_bytecode(code, mtime=0, source_size=0) – lapinkoira Oct 27 '15 at 10:59
  • This is just a hotfix, probably more things wont work, so I think it's just a bit buggy in python3.5 or it has some issues – lapinkoira Oct 27 '15 at 10:59
  • Ok sorry, I didn't really think. With this final change, it does build correctly. However, as you said, more things don't work: when I try to run the "compiled" program, I get: ```ImportError: No module named '_frozen_importlib_external' Fatal Python error: Py_Initialize: importlib install failed```. Who is to blame here ? Python 3.5 ? – JPFrancoia Oct 27 '15 at 11:34
  • 1
    Yes, I think it's not python3.5 compatible but with a quick glance to the source code I think yo ucould try python3.4. Would that be a problem? – lapinkoira Oct 27 '15 at 11:36
  • Yes it is haha. I don't want so setup a complete env just because one module is buggy. I'll try to fix the issue. Do you think it will be hard ? – JPFrancoia Oct 27 '15 at 11:50
1

Run this Command, it will fix your problem

python3 -m ensurepip --upgrade
pd farhad
  • 6,352
  • 2
  • 28
  • 47