How to Resolve CommandNotFoundException Error When Running Uvicorn for FastAPI in a Conda Environment? #137584
Replies: 3 comments 1 reply
-
Have you tried adding the scripts directory to PATH Uvicorn might be installed in the Scripts directory of your Conda environment, but this directory might not be in your PATH. You can add it manually:
Alternatively, you can permanently add this to your system PATH via Windows System Environment Variables. If this does not work try reinstall it but inside the correct environment
You can check if it is installed correctly using: |
Beta Was this translation helpful? Give feedback.
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Question
Body
I’m trying to run a FastAPI application using Uvicorn in a virtual environment created with Anaconda on Windows, but I’m encountering a CommandNotFoundException error. Here’s what I’ve done so far: Environment Setup Created a virtual environment named fastapi using Anaconda. Activated the environment in the Anaconda prompt. Installed Packages Installed FastAPI and Uvicorn using pip: pip install fastapi uvicorn Code in main.py I created a simple FastAPI application in main.py: from fastapi import FastAPI app = FastAPI() @app.get("/ping") async def ping(): return "Hello there!" Command Used to Run the App I tried running the app in the VS Code terminal with the following command: uvicorn main:app --reload However, I received the following error: PS C:\Users\HP\Anaconda_3\envs\fastapi\fastapi_projects> & C:/Users/HP/Anaconda_3/envs/fastapi/python.exe C:/Users/HP/Anaconda_3/envs/fastapi/fastapi_projects/main.py PS C:\Users\HP\Anaconda_3\envs\fastapi\fastapi_projects> 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 that the path is correct and try again. At line:1 char:1 + uvicorn main:app --reload + ~~~~~~~ + CategoryInfo : ObjectNotFound: (uvicorn:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException What I’ve Tried Verified that the virtual environment is activated. Reinstalled Uvicorn using pip install uvicorn. Checked the installation with pip show uvicorn, which confirms that Uvicorn is installed. Tried running Uvicorn directly with uvicorn main:app --reload, but still received the same error. Environment Details Operating System: Windows 11 Python Version: Python 3.12.4 Conda Version: conda 24.1.2 Virtual Environment: Created using Conda Development Environment: VS Code, with the project folder fastapi_projects inside the fastapi environment folder. Question What could be causing Uvicorn not to be recognized as a command, and how can I resolve this issue to run my FastAPI application successfully? Guidelines I have read and understood this category's guidelines before making this post.
Beta Was this translation helpful? Give feedback.
All reactions