cloudmatrix / esky

an auto-update framework for frozen python apps
BSD 3-Clause "New" or "Revised" License
362 stars 74 forks source link

Create compile_to_bytecode utility function. #68

Closed ghost closed 9 years ago

ghost commented 10 years ago

I haven't looked at what lazy imports are supposed to do, therefore I haven't imported the needed items until I know how I'm supposed to import them.

rfk commented 10 years ago

I haven't looked at what lazy imports are supposed to do

They're a bit of a hack to reduce startup overheads, you just make a function that does the import and returns the module. A suitable declaration would be something like:

if sys.version_info[:2] < (3, 4):
    importlib = None
else:
    @lazy_import
    def importlib():
        import importlib._bootstrap
        return importlib

Then you can just use importlib as if it has been imported directly.

ghost commented 10 years ago

It looks like py_compile uses a try/except block for loader.source_to_code: http://hg.python.org/cpython/file/3.4/Lib/py_compile.py#l122 where they raise PyCompileError.

How would you like to handle that? Use PyCompileError as they do, or something else?

nedy13 commented 10 years ago

Hi together... I have the same issue and find your pull request.

ValueError: bad marshal data (unknown type code) Fatal Python error: unable to locate initialization module

Current thread 0x00007f183204b700 (most recent call first): Abgebrochen (Speicherabzug geschrieben)

I tested your patch with git master repo and your patch. Fixed the issue. Thank you very much! My system: Archlinux with Python 3.4.1 and cx-Freeze 4.3.3