You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

打包后的Eel应用执行失败:AttributeError: 'NoneType'对象无write属性

Fix for AttributeError: 'NoneType' object has no attribute 'write' in Eel Bundled EXE

This error happens because when using the --noconsole flag with PyInstaller, the standard output (sys.stdout) and standard error (sys.stderr) streams are set to None. The Bottle framework (used internally by Eel) attempts to write to these streams during initialization, triggering the error.

Here are practical fixes:

1. Redirect stdout/stderr in your main script

Add this code at the very top of your survey.py file, before importing Eel:

import sys
import os
from io import StringIO

# Handle case where stdout/stderr are None (--noconsole mode)
if sys.stdout is None:
    # Option 1: Redirect to a log file for debugging
    log_dir = os.path.join(os.path.expanduser("~"), "MyAppLogs")
    os.makedirs(log_dir, exist_ok=True)
    log_path = os.path.join(log_dir, "app_output.log")
    sys.stdout = open(log_path, "a", encoding="utf-8")
    sys.stderr = open(log_path, "a", encoding="utf-8")
    
    # Option 2: Use a dummy null stream if you don't need logs
    # class NullWriter(StringIO):
    #     def write(self, msg):
    #         pass
    # sys.stdout = NullWriter()
    # sys.stderr = NullWriter()

# Now import Eel and rest of your code
import eel
# ... rest of your script ...

2. Use a custom PyInstaller spec file

Instead of relying on the python -m eel command, generate and modify a spec file:

  1. Generate the spec file:
    python -m eel survey.py web_folder --onefile --noconsole --spec
    
  2. Open the generated survey.spec file, and add this code at the top to handle streams:
    import os
    import sys
    if sys.stdout is None:
        sys.stdout = sys.stderr = open(os.devnull, 'w')
    
  3. Rebundle using the spec file:
    pyinstaller survey.spec
    

3. Downgrade Bottle to a compatible version

Newer Bottle versions have known issues with --noconsole mode. Try downgrading to version 0.12.20:

pip install bottle==0.12.20

Rebuild the EXE after downgrading.

Content of the question来源于stack exchange,提问作者Maryam Balti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 23:16:12