Skip to content

FileNotFoundError: [Errno 2] No such file or directory: '\.venv\\Scripts\\fastapi-forge' #109

@matteolavaggi

Description

@matteolavaggi

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

  1. Create a virtual environment on Windows
  2. Install fastapi-forge: pip install fastapi-forge
  3. Run the command: .venv/Scripts/fastapi-forge.exe start or fastapi-forge start
  4. Confirm that UV is installed when prompted
  5. 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:

  1. Check if sys.argv[0] exists, and if not, try appending .exe on Windows
  2. Use sys.executable and run as a module instead of using runpy.run_path(sys.argv[0])
  3. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions