Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cxfreeze aiohttp cannot import compat

I'm trying to use cx_freeze to build a binary dist for an web application written in Python 3 using the aiohttp package.

Basically I did:

cxfreeze server.py

and got a dist output

But when running the ./server binary, I got the following message:

  File "/usr/local/lib/python3.5/dist-packages/cx_Freeze/initscripts/__startup__.py", line 12, in <module>
    __import__(name + "__init__")
  File "/usr/local/lib/python3.5/dist-packages/cx_Freeze/initscripts/Console.py", line 24, in <module>
    exec(code, m.__dict__)
  File "server.py", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/aiohttp/__init__.py", line 10, in <module>
    from .protocol import *  # noqa
  File "/usr/local/lib/python3.5/dist-packages/aiohttp/protocol.py", line 17, in <module>
    from . import errors, hdrs
  File "/usr/local/lib/python3.5/dist-packages/aiohttp/errors.py", line 3, in <module>
    from asyncio import TimeoutError
  File "/usr/lib/python3.5/asyncio/__init__.py", line 21, in <module>
    from .base_events import *
  File "/usr/lib/python3.5/asyncio/base_events.py", line 32, in <module>
    from . import compat

ImportError: cannot import name 'compat'
like image 673
lang2 Avatar asked Jan 16 '17 04:01

lang2


1 Answers

Hopefully you've been able to fix this already, but for people searching this question like I was, I'll answer:

This compat module is part of asyncio, and not getting discovered by cx_Freeze. I had to add asyncio to the packages list in the build_exe options in setup.py to get it to be included:

setup(
    ...
    options = {
        'build_exe': {
            'packages': ['encodings', 'asyncio']
        },
    }
)
like image 181
justinian Avatar answered Sep 18 '22 14:09

justinian