Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

463
Visualizações
Running FastAPI multiple process error after pyinstaller

I am running python FastAPI with UVICORN with multiple processors (5 processes),It is running smoothly from the code, but when I tried make the exe from pyinstaller and try to run the file, it is showing error.

filename: main.py

import multiprocessing
import os

import uvicorn
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}


if __name__ == "__main__":
    multiprocessing.freeze_support()
    print("Running the instance")
    uvicorn.run("main:app", host="0.0.0.0", port=9000, workers=5)

Output code from source

python3 main.py

Running the instance
INFO:     Uvicorn running on http://0.0.0.0:9000 (Press CTRL+C to quit)
INFO:     Started parent process [17828]
INFO:     Started server process [17869]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Started server process [17870]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

I make a single file using pyinstaller with the following command

pyinstaller --onefile main.py

and while running the main file using

./main

get the following error

Running the instance
INFO:     Uvicorn running on http://0.0.0.0:9000 (Press CTRL+C to quit)
INFO:     Started parent process [18964]
ERROR:    Error loading ASGI app. Could not import module "main".
ERROR:    Error loading ASGI app. Could not import module "main".

How to refer the main:app, what is the actual class name after installer is created? I read somewhere that we need to use like foldername.main:app , but that also not working

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I tried your program and installing with

pyinstaller --onefile --hidden-import=main main.py

solved it for me.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda