使用PyInstaller创建的Python可执行文件中的运行时ImportError

时间:2019-04-04 00:55:04

标签: python windows pyinstaller python-asyncio

我正在尝试使用Python的asyncio模块,并拥有一个运行良好的简单脚本,但是当我使用PyInstaller对其进行编译并运行可执行文件时,会创建一个运行时ImportError,我无法弄清楚修理。 我花了几个小时在互联网上进行搜索,看看是否有人遇到过相同的问题,但是却找不到任何东西,而且我也不知道是什么引起了问题。

我正在编译的脚本如下:

import requests
import asyncio


async def main():
    loop = asyncio.get_event_loop()
    futures = [
        loop.run_in_executor(
            None,
            requests.get,
            'http://google.com'
        )
        for i in range(5)
    ]
    for response in await asyncio.gather(*futures):
        print(response.status_code)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

我用来编译脚本的命令是:

pyinstaller -F async_test.py

运行PyInstaller创建的可执行文件时引发的运行时异常是:

Traceback (most recent call last):
  File "asyncio\__init__.py", line 18, in <module>
ImportError: cannot import name '_overlapped'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "Miscellaneous\async_test.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "c:\users\username\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "asyncio\__init__.py", line 20, in <module>
OSError: [WinError 10022] An invalid argument was supplied
[13048] Failed to execute script async_test

我正在使用Python 3.6.4和PyInstaller 3.4

如果有人可以阐明问题所在以及解决方法,我将非常感激。

0 个答案:

没有答案