Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uvicorn is not working when called from the terminal

I tried installing uvicorn on the system via pip3 which worked, however i am unable to run the same from the command line. Any pointers as to how to resolve this?

Requirement already satisfied: uvicorn in /home/vhawk19/.local/lib/python3.7/site-packages (0.10.8)
Requirement already satisfied: uvloop>=0.14.0; sys_platform != "win32" and sys_platform != "cygwin" and platform_py
thon_implementation != "pypy" in /home/vhawk19/.local/lib/python3.7/site-packages (from uvicorn) (0.14.0)
Requirement already satisfied: websockets==8.* in /home/vhawk19/.local/lib/python3.7/site-packages (from uvicorn)
(8.1)
Requirement already satisfied: click==7.* in /home/vhawk19/.local/lib/python3.7/site-packages (from uvicorn) (7.0
)
Requirement already satisfied: h11==0.8.* in /home/vhawk19/.local/lib/python3.7/site-packages (from uvicorn) (0.8
.1)
Requirement already satisfied: httptools==0.0.13; sys_platform != "win32" and sys_platform != "cygwin" and platform
_python_implementation != "pypy" in /home/vhawk19/.local/lib/python3.7/site-packages (from uvicorn) (0.0.13)
vhawk19@api-server:~/api-server$ uvicorn
-bash: uvicorn: command not found```
like image 720
varun krishna Avatar asked Dec 01 '22 13:12

varun krishna


1 Answers

i recently install fastapi,uvicorn and tried to run

uvicorn main:app --reload

I am using zsh (shell type does not matter) and pyenv for virtual environment

got the same trouble (zsh: uvicorn command not found)

Solution which worked for me

python -m uvicorn main:app --reload

Why it worked

its because when we install uvicorn it install some system binaries which we may have to add to the path for the terminal to catch

else, we need to let the the terminal know about the binaries through python

like image 97
Shivachandra Avatar answered Dec 05 '22 07:12

Shivachandra