I'm trying to get my feet wet with Python's asyncio module and have a simple script that runs fine but when I compile it using PyInstaller and run the executable it creates I get a runtime ImportError that I can't figure out how to fix. I've spent several hours scouring the internet to see if anyone else has encountered the same issue but haven't been able to find anything and I don't understand what's causing the issue.
The script I'm compiling looks like this:
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())
The command I use to compile the script is:
pyinstaller -F async_test.py
And the runtime exception that is thrown when running the executable that PyInstaller creates is:
Traceback (most recent call last):
File "asyncio\__init__.py", line 18, in
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
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", 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
OSError: [WinError 10022] An invalid argument was supplied
[13048] Failed to execute script async_test
I'm using Python 3.6.4 and PyInstaller 3.4
If someone could shed some light on what the problem is and how to fix it I'd be very grateful.