• notice
  • Congratulations on the launch of the Sought Tech site

Use of multiple python/pip versions and uvicorn on Windows

    Use multiple versions of python, pip on windows and some things that need to be paid attention to when using uvicorn in the environment of the corresponding version. Make a note here.

    For example, I currently have two versions of python installed on my computer, namely Python3.8 and the latest Python3.11, and python3.11 is the latest python version I installed. Currently using python -V in the git command window on windows, the display is Python3.8.6, and there are multiple python projects in my current computer, some projects need to use the original version 3.8, and some need to use the new version 3.11, Showing that using python doesn't do what I intended.

    To use python3.11, you can make a copy of Python.exe in the same directory as the installation directory and name it as python311. Here, you need to be careful not to directly rename python.exe to python311.exe. In this case, use pip An error will be reported: Fatal error in launcher: Unable to create process using '"C:\Python311\python.exe" and other errors. I haven't tried it here, but I wonder if it is possible to solve it by setting the path of the exe file it is looking for when using pip, but the current method can already meet the conditions, and it doesn't matter.

    Basically we can start using python to install pip and use uvicorn service. Of course, you must first remember to write the two python directories and scripts directory into the environment variable, and then use the following method when using pip:

#In the original python version environment, use pip to view the list and install modules python - m pip listpython - m pip install uvicorn #3.11 version environment using pip to view the list and install modules python311 - m pip listpython311 - m pip install uvicorn

    After installing the uvicorn module, the default uvicorn is uvicorn.exe in the scripts folder in the two python versions. Directly using the uvicorn startup command will use the old version of python and its uvicorn by default. At this time, you need to add the scripts directory in the new python version Change the name of uvicorn in it, such as uvicorn311. Then you can use the following commands to start uvicorn project services in two python environments.

#Python project uvicorn under the old version main : app -- host = 127.0 . 0.1 -- port = 8000 -- reload
#Python project uvicorn311 in version 3.11 main : app -- host = 127.0 . 0.1 -- port = 8000 - - reload    


Technical otaku

Sought technology together

Related Topic


Leave a Reply