FastAPI: ModuleNotFoundError: No module named ‘uvicorn’

We Are Going To Discuss About FastAPI: ModuleNotFoundError: No module named ‘uvicorn’. So lets Start this Python Article.

FastAPI: ModuleNotFoundError: No module named ‘uvicorn’

  1. How to solve FastAPI: ModuleNotFoundError: No module named 'uvicorn'

    Check if you are calling the correct Gunicorn using which gunicorn (on Linux, or use where on Powerbash from Windows) from the terminal. If you are using a venv it should print a path pointing inside your venv directory.
    It happend to me also, because I followed the instruction from the Gunicorn page and installed using sudo apt install gunicorn. It could be a good option for your production container, where you'll probably run the application without a venv, but in developer mode on you machine it will work better if you install gunicorn inside your venv directory using the pip install gunicorn, using the pip from your venv.
    Then you can call it with python -m gunicorn main:app -k uvicorn.workers.UvicornWorker

  2. FastAPI: ModuleNotFoundError: No module named 'uvicorn'

    Check if you are calling the correct Gunicorn using which gunicorn (on Linux, or use where on Powerbash from Windows) from the terminal. If you are using a venv it should print a path pointing inside your venv directory.
    It happend to me also, because I followed the instruction from the Gunicorn page and installed using sudo apt install gunicorn. It could be a good option for your production container, where you'll probably run the application without a venv, but in developer mode on you machine it will work better if you install gunicorn inside your venv directory using the pip install gunicorn, using the pip from your venv.
    Then you can call it with python -m gunicorn main:app -k uvicorn.workers.UvicornWorker

Solution 1

Check if you are calling the correct Gunicorn using which gunicorn (on Linux, or use where on Powerbash from Windows) from the terminal. If you are using a venv it should print a path pointing inside your venv directory.

It happend to me also, because I followed the instruction from the Gunicorn page and installed using sudo apt install gunicorn. It could be a good option for your production container, where you’ll probably run the application without a venv, but in developer mode on you machine it will work better if you install gunicorn inside your venv directory using the pip install gunicorn, using the pip from your venv.

Then you can call it with python -m gunicorn main:app -k uvicorn.workers.UvicornWorker

Original Author Vash79 Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment