AttributeError in Python 3.11.5 with PyInstaller 6.3.0, NiceGUI, and Uvicorn: 'NoneType' object has no attribute 'fileno'

96 Views Asked by At

Question: How can I resolve this AttributeError related to Uvicorn in a PyInstaller-built application using NiceGUI? Is NiceGUI suitable for my objective of creating a cross-platform app for executing various Python scripts and connecting to different data sources? Or would you recommend a different approach or technology?

Environment: Python: 3.11.5 PyInstaller: 6.3.0 NiceGUI: 1.4.10 Uvicorn: 0.25.0 OS: Windows 10 Issue: I am encountering an AttributeError while running my Python application built with PyInstaller. The application uses NiceGUI and Uvicorn. The error is as follows:

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'

Basic Hello world:

from nicegui import ui

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

ui.run(native=True)

build file

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)

Future Goal and Objective: I aim to create an application that can execute various Python scripts to perform different functions. The app will connect to data sources like MSSQL Server, Snowflake, Salesforce, etc. Users will use this GUI to enter their credentials and execute various ETL functions or data manipulations.

Currently, I have tried using Tkinter, but it's creating issues with macOS compatibility. I need the app to work seamlessly on both Windows and macOS. I am considering NiceGUI as an alternative, hoping it wouldn't require users to go through massive installation issues, like installing Python and packages separately.

  1. Successful Compilation: You were expecting PyInstaller to successfully compile your Python application into a standalone executable. This executable should run without needing a separate Python installation or additional dependencies on the user's system.

  2. Functional GUI Application: The compiled application was expected to launch a window with a GUI, specifically a button. Clicking this button should trigger a notification, demonstrating basic interactivity.

1

There are 1 best solutions below

0
Anony Mous On

Have you tried reading this GitHub issue which talks about this? I believe that the below line:

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

needs to be changed to:

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

(According to this comment in the GitHub issue above, adding the semicolon is apparently pretty important.)

I can see that you may have sourced your code from a comment further down linked here, but maybe try add python and -m to the cmd list,

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

Try a combination of adding the semicolon and adding 'python -m', see if it works. Let me know if it does.