if name == "main":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)`
Application is running well through uvicorn or python main.py or fastapi dev
but i am trying to make build of my application through pyinstaller (command is below)
pyinstaller -F --onefile main.py
and when i am commenting the app.mount lines then the build is working fine, only it is giving below error for app.mout
PS C:\Users\Nitish Kumar\abc\cas-apis\dist> .\main.exe Database connection is active. Traceback (most recent call last): File "main.py", line 84, in <module> File "starlette\staticfiles.py", line 59, in __init__ RuntimeError: Directory 'app/static' does not exist [3076] Failed to execute script 'main' due to unhandled exception! PS C:\Users\Nitish Kumar\abc\cas-apis\dist> .\main.exe Database connection is active. Traceback (most recent call last): File "main.py", line 90, in <module> File "starlette\staticfiles.py", line 59, in __init__ RuntimeError: Directory 'C:\Users\NITISH~1\AppData\Local\Temp\_MEI144162\app/static' does not exist [9040] Failed to execute script 'main' due to unhandled exception! PS C:\Users\Nitish Kumar\abc\cas-apis\dist>
i checked everywhere like fastapi docs, google, chatgpt , still didn't get solution
Privileged issue
Issue Content
`app = FastAPI() base_dir = os.path.dirname(os.path.abspath(file))
Full paths for static and templates directories
static_dir = os.path.join(base_dir, "app/static") templates_dir = os.path.join(base_dir, "app/templates")
Mount the 'static' directory to serve static files
app.mount("/static", StaticFiles(directory=static_dir), name="static") app.mount("/templates", StaticFiles(directory=templates_dir), name="templates")
app.include_router(auths.auth)
if name == "main": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)`
Application is running well through uvicorn or
python main.py
orfastapi dev
but i am trying to make build of my application through pyinstaller (command is below)
pyinstaller -F --onefile main.py
and when i am commenting the app.mount lines then the build is working fine, only it is giving below error for app.mout
PS C:\Users\Nitish Kumar\abc\cas-apis\dist> .\main.exe Database connection is active. Traceback (most recent call last): File "main.py", line 84, in <module> File "starlette\staticfiles.py", line 59, in __init__ RuntimeError: Directory 'app/static' does not exist [3076] Failed to execute script 'main' due to unhandled exception! PS C:\Users\Nitish Kumar\abc\cas-apis\dist> .\main.exe Database connection is active. Traceback (most recent call last): File "main.py", line 90, in <module> File "starlette\staticfiles.py", line 59, in __init__ RuntimeError: Directory 'C:\Users\NITISH~1\AppData\Local\Temp\_MEI144162\app/static' does not exist [9040] Failed to execute script 'main' due to unhandled exception! PS C:\Users\Nitish Kumar\abc\cas-apis\dist>
i checked everywhere like fastapi docs, google, chatgpt , still didn't get solution