cxfreeze aiohttp无法导入compat

时间:2017-01-16 04:02:57

标签: python python-3.5 cx-freeze

我正在尝试使用cx_freeze为使用aiohttp包在Python 3中编写的Web应用程序构建二进制dist。

基本上我做了:

cxfreeze server.py

并获得dist输出

但是当运行./server二进制文件时,我收到以下消息:

  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 个答案:

答案 0 :(得分:15)

希望你已经能够解决这个问题了,但对于像我一样搜索这个问题的人,我会回答:

compat模块是asyncio的一部分,并且未被cx_Freeze发现。我必须将asyncio添加到packages build_exe选项中的setup.py列表中,以便将其包括在内:

setup(
    ...
    options = {
        'build_exe': {
            'packages': ['encodings', 'asyncio']
        },
    }
)