Bug Report: fastapi-forge fails on Windows with FileNotFoundError
Environment
- OS: Windows 11/10
- Python Version: 3.13
- fastapi-forge Version: 0.13.0
- Shell: Both PowerShell and Git Bash
- Installation Method:
pip install fastapi-forge
Description
When running fastapi-forge start on Windows, the application starts successfully and opens the NiceGUI interface on http://localhost:8777, but immediately crashes with a FileNotFoundError when trying to access the web interface.
Steps to Reproduce
- Create a virtual environment on Windows
- Install fastapi-forge:
pip install fastapi-forge
- Run the command:
.venv/Scripts/fastapi-forge.exe start or fastapi-forge start
- Confirm that UV is installed when prompted
- Try to access the web interface at
http://localhost:8777
Expected Behavior
The web interface should load successfully and allow the user to define database schema and service specifications.
Actual Behavior
The application crashes with the following error:
FileNotFoundError: [Errno 2] No such file or directory: '\.venv\\Scripts\\fastapi-forge'
Full Error Stack Trace
ERROR:nicegui:[Errno 2] No such file or directory: '\.venv\\Scripts\\fastapi-forge'
+ Exception Group Traceback (most recent call last):
| File "C:\Users\Pineapple\Documents\Visual Studio Code\ubli\ubli-be\.venv\Lib\site-packages\nicegui\ui_run.py", line 131, in run_script
| runpy.run_path(sys.argv[0], run_name='__main__')
| ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "<frozen runpy>", line 286, in run_path
| File "<frozen runpy>", line 254, in _get_code_from_file
| FileNotFoundError: [Errno 2] No such file or directory: '\.venv\\Scripts\\fastapi-forge'
Root Cause Analysis
The issue appears to be in how sys.argv[0] is handled on Windows. The executable is named fastapi-forge.exe, but sys.argv[0] returns fastapi-forge (without the .exe extension). When the code tries to use runpy.run_path(sys.argv[0]) in nicegui/ui_run.py, it fails because the file without the extension doesn't exist on Windows.
Verification
The file .venv/Scripts/fastapi-forge.exe exists and can be executed, confirming the installation is correct. The issue is purely with the internal path resolution.
$ ls .venv/Scripts/fastapi-forge*
.venv/Scripts/fastapi-forge.exe
Suggested Fix
The code should handle Windows executable extensions properly. Possible solutions:
- Check if
sys.argv[0] exists, and if not, try appending .exe on Windows
- Use
sys.executable and run as a module instead of using runpy.run_path(sys.argv[0])
- Add platform-specific handling in the NiceGUI integration code
Workaround Attempted
Tried running as a Python module:
python -m fastapi_forge start
But fastapi_forge is not importable as a module (ModuleNotFoundError).
Additional Context
This appears to be a common issue with Python CLI tools on Windows when they use sys.argv[0] for script introspection. The NiceGUI framework's ui_run.py is trying to reload/run the script, which fails on Windows due to the missing .exe extension.
Related Files
The error originates from:
nicegui/ui_run.py:131 - calls runpy.run_path(sys.argv[0])
- The fastapi-forge entry point that's executed by Windows
Would appreciate any guidance on this issue or if there's a workaround I'm missing. Thank you!
Bug Report: fastapi-forge fails on Windows with FileNotFoundError
Environment
pip install fastapi-forgeDescription
When running
fastapi-forge starton Windows, the application starts successfully and opens the NiceGUI interface onhttp://localhost:8777, but immediately crashes with aFileNotFoundErrorwhen trying to access the web interface.Steps to Reproduce
pip install fastapi-forge.venv/Scripts/fastapi-forge.exe startorfastapi-forge starthttp://localhost:8777Expected Behavior
The web interface should load successfully and allow the user to define database schema and service specifications.
Actual Behavior
The application crashes with the following error:
Full Error Stack Trace
Root Cause Analysis
The issue appears to be in how
sys.argv[0]is handled on Windows. The executable is namedfastapi-forge.exe, butsys.argv[0]returnsfastapi-forge(without the.exeextension). When the code tries to userunpy.run_path(sys.argv[0])innicegui/ui_run.py, it fails because the file without the extension doesn't exist on Windows.Verification
The file
.venv/Scripts/fastapi-forge.exeexists and can be executed, confirming the installation is correct. The issue is purely with the internal path resolution.$ ls .venv/Scripts/fastapi-forge* .venv/Scripts/fastapi-forge.exeSuggested Fix
The code should handle Windows executable extensions properly. Possible solutions:
sys.argv[0]exists, and if not, try appending.exeon Windowssys.executableand run as a module instead of usingrunpy.run_path(sys.argv[0])Workaround Attempted
Tried running as a Python module:
But
fastapi_forgeis not importable as a module (ModuleNotFoundError).Additional Context
This appears to be a common issue with Python CLI tools on Windows when they use
sys.argv[0]for script introspection. The NiceGUI framework'sui_run.pyis trying to reload/run the script, which fails on Windows due to the missing.exeextension.Related Files
The error originates from:
nicegui/ui_run.py:131- callsrunpy.run_path(sys.argv[0])Would appreciate any guidance on this issue or if there's a workaround I'm missing. Thank you!