Python uvicorn : The term 'uvicorn' is not recognized as the name of a cmdlet, function, script file

11,676

Solution 1

Python install his scripts in c:\users\username\appdata\roaming\python\python39\scripts\ put this in the system and user variable path will solve the problem.

Solution 2

You can also run uvicorn with the following command:

python -m uvicorn main:app --reload

Solution 3

first, you have to run

virtualenv env

then install code

pip install fastapi uvicorn

Solution 4

I Have The Same Problem and Found i dont Activate my Virtual Environment

After Activating Virtual Environment uvicorn Example:app --reload Worked For me

Maybe The Problem is so simple Like This

Share:
11,676
Erik hoeven
Author by

Erik hoeven

Updated on June 25, 2022

Comments

  • Erik hoeven
    Erik hoeven 6 months

    Good evening,

    I am using python 3.9 and try to run a new FastAPI service on Windows 10 Pro based on the documentation on internet https://www.uvicorn.org/ i executed the following statements

    pip install uvicorn pip install uvicorn[standard]
    

    create the sample file app.py

    from fastapi import FastAPI
    app = FastAPI()
    @app.get("/")
    async def root():
        return {"message": "Hello World"}
    

    But when i run the code below :

    uvicorn main:app --reload
    uvicorn : The term 'uvicorn' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify t
    hat the path is correct and try again.
    At line:1 char:1
    + uvicorn
    + ~~~~~~~
        + CategoryInfo          : ObjectNotFound: (uvicorn:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    

    I also add the path of Python in the envroment settings

    I also re-install Python 3.9 and make the default path for installation to c:\ProgramFiles\Python39 this path is also include now in the system enviroment and user enviroment settings.

    enter image description here

    if i run pip install uvicorn again it shows the following statement:

    λ pip install uvicorn
    Defaulting to user installation because normal site-packages is not writeable
    Requirement already satisfied: uvicorn in c:\users\username\appdata\roaming\python\python39\site-packages (0.12.2)
    Requirement already satisfied: h11>=0.8 in c:\users\username\appdata\roaming\python\python39\site-packages (from uvicorn) (0.11.0)
    Requirement already satisfied: click==7.* in c:\users\username\appdata\roaming\python\python39\site-packages (from uvicorn) (7.1.2)
    WARNING: You are using pip version 20.2.3; however, version 20.2.4 is available.
    You should consider upgrading via the 'c:\program files\python39\python.exe -m pip install --upgrade pip' command.
    

    Many thanks

    Erik

    • John Gordon
      John Gordon about 2 years
      Try adding \pip to the end of that path.
    • Erik hoeven
      Erik hoeven about 2 years
      @John: I did what you say! But it does not solve the problem yet! See adjusted question
    • John Gordon
      John Gordon about 2 years
      Hmm. Try %APPDATA%\Python instead?
    • Erik hoeven
      Erik hoeven about 2 years
      @John thanks for the fast reply. It is still not working. I have changed the question again
    • lsabi
      lsabi about 2 years
      Have you tried installing it with pip3 install ... ?
    • Erik hoeven
      Erik hoeven about 2 years
      Hi Isabi, yes I also tried that, but that didn't work
  • Erik hoeven
    Erik hoeven about 2 years
    Hi Ognyan! thanks for the reply of the solution. I found the solution of this problem. And it is in system path variable. It seams that Python install the script s in c:\users\username\appdata\roaming\python\python39\scripts\
  • Erik hoeven
    Erik hoeven about 2 years
    But thanks to the removal script a saw where the uvicorn.exe is placed.
  • Nathan Mersha
    Nathan Mersha 11 months
    if python does not work use python3 instead