0

I am building a Python 3.11 Flask-SocketIO project into an .exe using PyInstaller on Jenkins (Windows 10). The project works fine when I run it locally with python runapp.py or even inside Jenkins using python runapp.py. But when I run the generated .exe from PyInstaller, I always get:

ValueError: Invalid async_mode specified

I force async_mode="gevent" in my __init__.py:

import gevent.monkey
gevent.monkey.patch_all()

from flask_socketio import SocketIO
socketio = SocketIO(app, cors_allowed_origins="*", async_mode="gevent")

All dependencies are installed (gevent==25.8.2, gevent-websocket==0.10.1, greenlet==3.2.4, Flask-SocketIO==5.3.6, etc). eventlet has been removed to avoid conflicts.

My .spec includes:

hiddenimports = [
    'gevent',
    'gevent.monkey',
    'gevent.threading',
    'gevent._socket3',
    'gevent._threading',
    'gevent._semaphore',
    'gevent.builtins',
    'geventwebsocket',
    'greenlet',
    'engineio.async_drivers.threading',
    'engineio.async_drivers.gevent',
    'engineio.async_drivers.gevent_uwsgi',
    'engineio.async_drivers.aiohttp',
    'asyncio',
]

When running PyInstaller I also see warnings like:

ERROR: Hidden import 'engineio.async_drivers.asyncio' not found

But I verified that asyncio is available at: C:\Users\Innopharm\AppData\Local\Programs\Python\Python311\Lib\asyncio

Why does this work fine when running python runapp.py, but fails when running the PyInstaller .exe? What am I missing in PyInstaller hidden imports or configuration?

for more additional information the output from the runapp.exe:

Traceback (most recent call last): File "runapp.py", line 2, in <module> File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 378, in exec_module File "theone\__init__.py", line 97, in <module> File "flask_socketio\__init__.py", line 187, in __init__ File "flask_socketio\__init__.py", line 243, in init_app File "socketio\base_server.py", line 31, in __init__ File "engineio\base_server.py", line 81, in __init__ ValueError: Invalid async_mode specified [PYI-9784:ERROR] Failed to execute script 'runapp' due to unhandled exception!

I expect the EXE can run

6
  • is this full error? always put full error message (traceback) because there are other useful information. Commented Oct 2 at 11:03
  • 1
    maybe engineio.async_drivers.asyncio and \Lib\asyncio are two different objects. And when you don't add engineio.async_drivers.asyncio then \Lib\asyncio may not work. Commented Oct 2 at 11:04
  • @furas 47766 ERROR: Hidden import 'engineio.async_drivers.asyncio' not found. that is output from jenkins and i will edit my post to add the error output Commented Oct 3 at 2:03
  • @furas if you want my full code and files i can send you via email Commented Oct 3 at 2:07
  • I don't want code via email - on Stackoverflow code has to be in question, not in email or links to external places. But I think it doesn't need full code. You have to check if there is engineio and if it has .async_drivers.asyncio, not \Lib\asyncio - because it is not the same. it seems engineio can mean module python-engineio Commented Oct 3 at 12:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.