Python 3.11.5 与 PyInstaller 6.3.0、NiceGUI 和 Uvicorn 中的 AttributeError:“NoneType”对象没有属性“fileno”

问题描述 投票:0回答:1

问题: 如何使用 NiceGUI 在 PyInstaller 构建的应用程序中解决与 Uvicorn 相关的 AttributeError? NiceGUI 是否适合我创建跨平台应用程序来执行各种 Python 脚本并连接到不同数据源的目标?或者您会推荐不同的方法或技术吗?

环境: 蟒蛇:3.11.5 py安装程序:6.3.0 NiceGUI:1.4.10 独角兽:0.25.0 操作系统:Windows 10 问题: 我在运行使用 PyInstaller 构建的 Python 应用程序时遇到 AttributeError。该应用程序使用 NiceGUI 和 Uvicorn。错误如下:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
  File "nicegui\ui_run.py", line 171, in run
    ChangeReload(config, target=Server.instance.run, sockets=[sock]).run()
  File "uvicorn\supervisors\basereload.py", line 49, in run
  File "uvicorn\supervisors\basereload.py", line 82, in startup
  File "uvicorn\_subprocess.py", line 37, in get_subprocess
AttributeError: 'NoneType' object has no attribute 'fileno'

基本的你好世界:

from nicegui import ui

ui.button('Show Notification', on_click=lambda: ui.notify('Button Clicked'))

ui.run(native=True)

构建文件

import os
import subprocess
from pathlib import Path
import nicegui

cmd = [
    'PyInstaller',
    '--name', 'MyButton',
    '--onefile',
    '--windowed', 
    '--add-data', f'{Path(nicegui.__file__).parent}{os.pathsep}nicegui',
    '--clean',
    'main.py' 
]

print(f'Command: {cmd}')
subprocess.call(cmd)

未来的目标: 我的目标是创建一个可以执行各种Python脚本来执行不同功能的应用程序。该应用程序将连接到 MSSQL Server、Snowflake、Salesforce 等数据源。用户将使用此 GUI 输入其凭据并执行各种 ETL 函数或数据操作。

目前,我尝试使用 Tkinter,但它造成了 macOS 兼容性问题。我需要该应用程序能够在 Windows 和 macOS 上无缝运行。我正在考虑使用 NiceGUI 作为替代方案,希望它不会要求用户经历大量的安装问题,例如分别安装 Python 和软件包。

  1. 成功编译:您期望 PyInstaller 成功将您的 Python 应用程序编译为独立的可执行文件。该可执行文件应该无需单独的 Python 安装或对用户系统的额外依赖即可运行。

  2. 功能性 GUI 应用程序:编译后的应用程序预计会启动一个带有 GUI 的窗口,特别是一个按钮。单击此按钮应触发通知,展示基本的交互性。

python-3.x pyinstaller uvicorn nicegui
1个回答
0
投票

您是否尝试过阅读this 讨论此问题的 GitHub 问题?我相信下面这行:

'--add-data', f'{Path(nicegui.__file__).parent}{os.pathsep}nicegui',

需要更改为:

# static_dir = Path(nicegui.__file__).parent
'--add-data="{static_dir};nicegui"'

(根据上面 GitHub 问题中的此评论,添加分号显然非常重要。)

我可以看到您可能从链接这里的评论中获取了代码,但也许可以尝试将

python
-m
添加到
cmd
列表中,

cmd = [
    'python',
    '-m',
    ...

尝试添加分号和添加

'python -m'
的组合,看看是否有效。如果有请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.