Fast API Manage Dependencies and Ensure a Stable Development Environment
Creating a virtual environment is a fundamental practice in Python development, especially when working with frameworks like Fast API. The primary reason for using a virtual environment is to create an isolated space for your project’s dependencies. This isolation ensures that the project uses specific versions of libraries and frameworks, like FastAPI itself, independent of the versions installed globally on your system.
We are going to set up Venv, which is to create your own virtual environment for the fast API. So, the first thing we need to do is type the “Pip list” in the command prompt.
C:\Users\zakir>pip list
Pip list is going to show us everything that we have downloaded on our personal machine without using a virtual environment. So just to kind of show what we currently have installed, we have a bunch of things installed, and we can see that the fast in not installed.
Create Fast API Virtual Environment
To create our virtual environment, the very first thing we need to do is CD into documents directory and then make a new directory called KaiBot.
C:\Users\zakir\Documents>mkdir Kaibot
We can then see there is nothing currently in our KatBot directory. Well, now, create our virtual environment, and our virtual environment will be inside our KaiBot directory. We can create our fast API environment by doing python dash m venv fastapienv.
C:\Users\zakir\Documents\Kaibot> python -m venv fastapienv
Now, we can see that fast API env is inside this directory.
Activate Fast API
However, our fast API environment is not active and need to make sure that we activate it so we can install fast API.
C:\Users\zakir\Documents\KaiBot>fastapienv\Scripts\activate.bat
(fastapienv) C:\Users\zakir\Documents\KaiBot>