anakaine
anakaine

Reputation: 1248

Uvicorn: ''uvicorn' is not recognized as an internal or external command, operable program or batch file.' Windows

I've been attempting to install Uvicorn for use with FastAPI, on Windows 10.

I'm encountering an error when running from the command prompt that reads 'uvicorn' is not recognized as an internal or external command, operable program or batch file.

I'm running Python 3.10.7, with the following in my PATH environment variable

C:\Python310\   
C:\Python310\Scripts

I've attempted to install Uvicorn with pip using either of the following, including an uninstall between versions, uninstalling both and trying again, etc.

pip install uvicorn
pip install uvicorn[standard]

This does not appear to place a uvicorn.exe file in C:\Python310\Scripts\, which is what I'd expect given that most other things in that folder that can be called directly from cmd are executables. Then again, I'm not actually sure what is normal behaviour here as a first time uvicorn user.

The error is generated when I open up a command prompt and type uvicorn. Of course, uvicorn my_app:app doesn't work.

The following, however, does work:

Open command prompt   
> Python   
>>>import uvicorn   
>>>   

I have not set up a virtual environment.

Any thoughts on what might be going on would be appreciated. The uvicorn front page simply suggests using pip and everything is all good to go. Can I not use the uvirorn my_app:app method to start uvicorn on Windows? The getting started docs only mention the one method of starting (there is mention of importing uvicorn into a script, but it's mentioned once, and not through any of the typical deployment patterns).

Upvotes: 2

Views: 3794

Answers (1)

anakaine
anakaine

Reputation: 1248

The issue has been resolved.

The main issue was that the Python 3.10.7 had been installed not for all users, but had been installed in a path in C:\ making it look like it was installed for all users. As @Bijay pointed out uvicorn was then installing via pip to the appdata\roaming\python directory instead of that which was mapped in the PATH variable. This was also the cause of some other permissions issues.

A full uninstall of python, manual cleanup of those directories and paths after uninstall, a restart, then a reinstall with the python installer using the custom and 'for all users' option resolved the issue. Install uvicorn with pip.

Upvotes: 1

Related Questions