pythonpyinstallerauto-py-to-exeeel

Error when packaging eel project to an exe


I am building an python project with Eel, and I'm trying to package my program to an exe with PyInstaller as instructed in the documentation. However, I get the following error when I open the .exe:

Error

Traceback (most recent call last):
  File "hello.py", line 1, in <module>
    import eel
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "eel\__init__.py", line 8, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "bottle.py", line 73, in <module>
AttributeError: 'NoneType' object has no attribute 'write'

I tried to use auto py-to-exe instead of Pyinstaller, but I got the same error. Finally, I tried to package the Eello world example from the Eel documentation to see if it was my program that was the issue, but I still got the same error. I found a similiar problem in a github issue, but I fail to see what I should attach to --add-data.

I am running Python 3.10.8 and Eel 0.14.0. I've now tried python 3.8.9 and python 3.9.13 without luck.

Update

Upon further investigation, I discovered that the error only occours when I attach --noconsole at the end of my cmd python -m eel hello.py web --onefile --noconsole . However, I want my app to work without a visible console.


Solution

  • One of the libraries you are using is attempting to write to sys.stdout and sys.stderr, which are set to None when you run pyinstaller with --windowed option.

    You need to explicitly set sys.stderr and sys.stdout in your programs code as early as possible to a writeable object like an open file or an io buffer.

    for example:

    import sys
    
    outfile = open("logfile.txt", "wt")
    sys.stderr = outfile
    sys.stdout = outfile