Setting Your Own Fast API Virtual Environment

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>

Now, this will start our fast API environment and it is activated because we can see in the very beginning it has parentheses Fast API environment before the path and now we know that, we have our fast API environment active.

If we go ahead and type Pip List then we can see there is only two things installed. Next things, we need to install in our environment is fast API and uvicorn which is web server for fast API.

Now, inside of our environment we can say Pip list where we can see fast API, uvicorn, and some other things are installed and that is all we need to create a virtual environment for our application.

Leave a Comment

Your email address will not be published. Required fields are marked *