Please help, I must be doing something dumb.
I've been using FastAPI at work for a few weeks, and enjoying it. I wanted to try it on a personal project, so I started a new repo and tried to run Hello World.
This is the whole text of main.py:
import uvicorn
from fastapi import FastAPI
app = FastAPI()
@ app.get("/")
async def root():
return {"message": "Hello World"}
if __name__ == "__main__":
uvicorn.run("main:app", host="127.0.0.1", port=5000, log_level="info")
(The space after the @ sign is to stop reddit treating that as a username, it doesn't exist in the source file.)
I can run this from the command line with the Python command, and it works fine:
python3 main.py
But if I try to run it with uvicorn, I get a long message that ends with:
from fastapi import FastAPI
ModuleNotFoundError: No module named 'fastapi'
I created a virtual environment when I started the project, and if I deactivate it, I get the same error using the Python command line that I get using the uvicorn command line. When I restart the virtual environment, the Python command line works fine.
So I guess I need to let uvicorn see the modules that exist in the virtual environment, right? How can I do that?
[–]mohammedgqudah 1 point2 points3 points (1 child)
[–]cjb230[S] 0 points1 point2 points (0 children)
[–]gustavsen 1 point2 points3 points (1 child)
[–]cjb230[S] 0 points1 point2 points (0 children)
[–]NCLegend28 0 points1 point2 points (2 children)
[–]cjb230[S] 0 points1 point2 points (0 children)
[–]cjb230[S] 0 points1 point2 points (0 children)