Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Virtual Environment

Virtual Environment

A virtual environment is like a mini Python world inside your computer where you can install Python libraries just for one project, without affecting other projects or your system Python.

Why Use It?

Imagine you have two Python projects:

  • Project A needs Django version 3.2
  • Project B needs Django version 4.0

Without a virtual environment, installing both could cause conflicts.

✅ With virtual environments:

  • Project A has its own isolated space
  • Project B has a separate environment with its own packages

How to Create and Use a Virtual Environment

🔹 Step 1: Open Terminal / Command Prompt

🔹 Step 2: Navigate to your project folde

cd path_to_your_project_folder

🔹 Step 3: Create a virtual environment

python -m venv env

Here, env is just the name of the virtual environment folder (you can name it anything).

🔹 Step 4: Activate it

  • Windows:
env\Scripts\activate

  • macOS/Linux:
source env/bin/activate

✅ After activation, your terminal will look like:

(env) C:\your\project\folder>

🔹 Step 5: Install packages inside it

pip install numpy
pip install flask

These libraries will be installed only in this environment, not globally.

🔹 Step 6: Deactivate when done

deactivate

Summary

TermMeaning
Virtual EnvIsolated space for Python + packages
Why use it?Avoid conflicts between different projects
Tool usedvenv (built-in module in Python)

Example Use Case

You’re working on a Flask web app and want to install Flask only for that project.

Using a virtual environment:

python -m venv env
source env/bin/activate
pip install flask

Now Flask is available only inside this project!

    Leave a Reply

    Your email address will not be published.

    Need Help?