Python VirtualEnv

Python · Tooling & Errors

Theory

A virtual environment is a self-contained folder with its own Python interpreter link and its own set of installed packages, separate from the system Python and from other projects. python -m venv .venv creates one; activating it (source .venv/bin/activate on macOS/Linux, .venv\Scripts\activate on Windows) makes python and pip in that terminal point to it.

After activation, pip install pandas installs pandas only into .venv. Project A can use one version of a library and project B another without conflict. deactivate returns to the global Python. The usual workflow is: create the venv, activate it, install packages, save them with pip freeze > requirements.txt, and add .venv to .gitignore so the folder itself is never committed.

Why we use it

Different projects need different package versions, and installing everything globally eventually breaks something. A virtual environment keeps each project's dependencies isolated and reproducible.

When to use it

Create one for every real project, before installing packages. Only throwaway experiments can skip it. conda environments or tools like poetry and uv offer the same isolation with extra features.

How it works

  1. Start a new project folder
  2. python -m venv .venv
  3. Activate the environment
  4. pip install the packages you need
  5. pip freeze > requirements.txt
  6. Done working? Yes: Run deactivate. No: Keep coding inside the venv.
  7. Project dependencies stay isolated

Syntax

python -m venv env_name
source env_name/bin/activate

Example

python -m venv .venv
source .venv/bin/activate
pip install pandas

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic