pythonpipfastapimsys2

Can't find command fastapi for Python on MSYS2


I want to make the Python fastapi work with MSYS2.

I work from the MSYS2 MinGW x64 shell. I have the following installed using the commands:

pacman -S mingw-w64-x86_64-python
pacman -S mingw-w64-x86_64-python-pip
pacman -S mingw-w64-x86_64-python-fastapi

and I also ran

pip install fastapi

which gave the output

imelf@FLORI-LENOVO-93 MINGW64 /c/Users/imelf/Documents/NachhilfeInfoUni/Kadala/Pybind11
$ pip install fastapi
Requirement already satisfied: fastapi in c:/software/msys64/mingw64/lib/python3.11/site-packages (0.109.0)
Requirement already satisfied: pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4 in c:/software/msys64/mingw64/lib/python3.11/site-packages (from fastapi) (2.5.3)
Requirement already satisfied: starlette<0.36.0,>=0.35.0 in c:/software/msys64/mingw64/lib/python3.11/site-packages (from fastapi) (0.35.0)
Requirement already satisfied: typing-extensions>=4.8.0 in c:/software/msys64/mingw64/lib/python3.11/site-packages (from fastapi) (4.9.0)
Requirement already satisfied: annotated-types>=0.4.0 in c:/software/msys64/mingw64/lib/python3.11/site-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi) (0.6.0)
Requirement already satisfied: pydantic-core==2.14.6 in c:/software/msys64/mingw64/lib/python3.11/site-packages (from pydantic!=1.8,!=1.88.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi) (2.14.6)
Requirement already satisfied: anyio<5,>=3.4.0 in c:/software/msys64/mingw64/lib/python3.11/site-packages (from starlette<0.36.0,>=0.35.0->fastapi) (4.2.0)
Requirement already satisfied: idna>=2.8 in c:/software/msys64/mingw64/lib/python3.11/site-packages (from anyio<5,>=3.4.0->starlette<0.36.0,>=0.35.0->fastapi) (3.6)
Requirement already satisfied: sniffio>=1.1 in c:/software/msys64/mingw64/lib/python3.11/site-packages (from anyio<5,>=3.4.0->starlette<0.36.0,>=0.35.0->fastapi) (1.3.0)

Now I have this file test.py with the following content:

from fastapi import FastAPI

meine_coole_rest_api = FastAPI()

@meine_coole_rest_api.get("/")
async def wurzel_pfad():
   return {"coole_nachricht" : "Fast API works"}

Trying to launch it with as described in this tutorial

fastapi dev test.py

gives the error message

imelf@FLORI-LENOVO-93 MINGW64 /c/Users/imelf/Documents/NachhilfeInfoUni/Kadala/Pybind11
$ fastapi dev test.py
bash: fastapi: command not found

Why does he not recognize the command? How do I install fastapi correctly?


Solution

  • fastapi doesn't ship with the CLI anymore by default, you can install it using pip install fastapi-cli