🟡 Advanced Python  ·  Lesson 26

pip, venv and Project Environment

pip, venv और Project Environment

What is Virtual Environment and pip?

Virtual Environment and pip means a virtual environment keeps project dependencies separate. pip installs and manages Python packages.

In real programs, this topic helps in installing libraries safely. Learn the idea first, then type the program yourself and compare the output.

💡 At a Glance
PointDetails
Course AreaCore Python
Basic programming concepts used to write Python programs.
Main Useinstalling libraries safely
Example Filevirtualenv-pip.py
Practice FocusRun, change values, and explain the output line by line.

Why should you learn this?

  • It is useful for installing libraries safely.
  • It connects with keeping project packages separate.
  • It improves your ability to read, write and debug Python programs.

Important Terms

These terms are used directly in this lesson. Understand them before memorising the code.

TermMeaning
venvvenv is an important term in this topic.
pip installpip install is an important term in this topic.
requirements.txtFile listing packages needed to recreate the project environment.
dependencyExternal library required by a project.
project setupproject setup is an important term in this topic.

Syntax / Basic Pattern

These are terminal/command prompt commands. Type them one by one; do not paste them inside a Python file.

Terminal commands
python -m venv .venv

# Windows
.venv\Scripts\activate

# macOS/Linux
source .venv/bin/activate

pip install pandas numpy matplotlib
pip freeze > requirements.txt

Complete Example Program

Terminal commands
python -m venv .venv

# Windows
.venv\Scripts\activate

# macOS/Linux
source .venv/bin/activate

pip install pandas numpy matplotlib
pip freeze > requirements.txt

Expected Output

(.venv) pip install pandas numpy matplotlib Successfully installed ...

Program Explanation

  • python -m venv .venv performs the next step of the program logic.
  • .venv\Scripts\activate performs the next step of the program logic.
  • source .venv/bin/activate performs the next step of the program logic.
  • pip install pandas numpy matplotlib performs the next step of the program logic.
  • pip freeze > requirements.txt performs the next step of the program logic.

Where will you use it?

  • Installing libraries safely.
  • Keeping project packages separate.
  • Sharing requirements.txt.

Common Mistakes

  • Writing code with wrong indentation.
  • Using input() value directly in calculations without converting it to int or float.
  • Using unclear variable names that make the program difficult to understand.

Practice Tasks

  1. Type the program in virtualenv-pip.py and run it.
  2. Change input values or sample data and observe the new output.
  3. Create one example related to installing libraries safely.
  4. Write 5 lines explaining the logic in your own words.

Summary

Virtual Environment and pip is not a theory-only topic. You should be able to explain the meaning, write the example, run it successfully, and use it in a small practical program.

Virtual Environment और pip क्या है?

Virtual Environment और pip ka matlab hai: A virtual environment keeps project dependencies separate. pip installs and manages Python packages. Simple words me, ye topic practical Python programs likhne me direct use hota hai.

Is topic ko sirf definition ke liye nahi, balki installing libraries safely jaise real examples ke liye practice karein.

यह क्यों सीखना जरूरी है?

  • Ye installing libraries safely me kaam aata hai.
  • Ye keeping project packages separate se bhi connected hai.
  • Isse aap code ka output aur errors better samajh paate hain.

Important Terms

TermMeaning
venvvenv is an important term in this topic.
pip installpip install is an important term in this topic.
requirements.txtFile listing packages needed to recreate the project environment.
dependencyExternal library required by a project.
project setupproject setup is an important term in this topic.

Syntax / Basic Pattern

Ye commands terminal/command prompt me type karni hain, Python file ke andar nahi.

Terminal commands
python -m venv .venv

# Windows
.venv\Scripts\activate

# macOS/Linux
source .venv/bin/activate

pip install pandas numpy matplotlib
pip freeze > requirements.txt

Complete Example Program

Terminal commands
python -m venv .venv

# Windows
.venv\Scripts\activate

# macOS/Linux
source .venv/bin/activate

pip install pandas numpy matplotlib
pip freeze > requirements.txt

Expected Output

(.venv) pip install pandas numpy matplotlib Successfully installed ...

Program Explanation

  • python -m venv .venv performs the next step of the program logic.
  • .venv\Scripts\activate performs the next step of the program logic.
  • source .venv/bin/activate performs the next step of the program logic.
  • pip install pandas numpy matplotlib performs the next step of the program logic.
  • pip freeze > requirements.txt performs the next step of the program logic.

Practical Uses

  • Installing libraries safely.
  • Keeping project packages separate.
  • Sharing requirements.txt.

Common Mistakes

  • Writing code with wrong indentation.
  • Using input() value directly in calculations without converting it to int or float.
  • Using unclear variable names that make the program difficult to understand.

Practice Tasks

  1. Program ko virtualenv-pip.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. installing libraries safely par ek छोटा example banayen.
  4. Logic ko apne words me 5 lines me likhein.

सारांश

Virtual Environment and pip ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.

← Back to Python Tutorial