Registrations Closing Soon for DevOps Certification Training by CloudxLab | Registrations Closing inEnroll Now
What is a Virtual Environment?
As the name suggests, it is an environment virtually created to isolate the projects.
This isolation helps to avoid discrepancies between the different versions of the libraries or packages as used by different projects in our system.
Why do we use a Virtual Environment?
Say, we have installed Flask Framework of version 1.1 some time ago, and have built an app(say App A) based on that.
Later, if we want to build an app(say App B) with the latest version of Flask, we need to upgrade Flask.
Now that we have upgraded Flask on our system, we no longer will be able to run the App A smoothly, due to the differences in the versions.
Virtual environments come to the rescue. If we create the two apps in 2 different virtual environments and install the corresponding packages or libraries in each virtual environment, both the apps run smoothly.
For the above-mentioned reasons, it is a best practice to create any project in a virtual environment. We can create any number of virtual environments which is an incredible thing.
How to create and use a Virtual Environment?
Creating a Virtual Environment:
virtualenv <<your virtual environment name>>.
virtualenv my_first_venv creates a virtual environment named
Activating a Virtual Environment:
After creating the virtual environment, we switch to that environment to create our project and install the dependencies inside that environment.
We switch to a virtual environment by using:
source <<your virtual environment name>>/bin/activate
source my_first_venv/bin/activate command switches to the virtual environment named
Deactivating a Virtual Environment:
The following commands should be executed in the console.
If you haven't yet switched to
Image-Classification-App directory yet, perform
cd ~ cd Image-Classification-App
Let us create a virtual environment for the Flask App we are going to build now.
Create a virtual environment named
Img-Class-Env using the command
Activate the virtual environment
No hints are availble for this assesment
Answer is not availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here