🟡 Advanced Python · Lesson 26
pip, venv और Project Environment
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
| Term | Meaning |
|---|---|
| venv | venv is an important term in this topic. |
| pip install | pip install is an important term in this topic. |
| requirements.txt | File listing packages needed to recreate the project environment. |
| dependency | External library required by a project. |
| project setup | project 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 .venvperforms the next step of the program logic..venv\Scripts\activateperforms the next step of the program logic.source .venv/bin/activateperforms the next step of the program logic.pip install pandas numpy matplotlibperforms the next step of the program logic.pip freeze > requirements.txtperforms 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
- Program ko
virtualenv-pip.pyfile me type karke run karein. - Values change karke output compare karein.
- installing libraries safely par ek छोटा example banayen.
- 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.