cxfreeze aiohttp cannot import compat

扶醉桌前 提交于 2019-12-07 02:26:38

问题


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'

回答1:


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']
        },
    }
)


来源:https://stackoverflow.com/questions/41669260/cxfreeze-aiohttp-cannot-import-compat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!