SwadhyAI Notes

All Python notes

Python PIP 📦

Package Management

PIP is the standard package manager for Python. It allows you to install and manage additional libraries and dependencies that are not part of the Python standard library.

🛍️ Analogy: The App Store

Think of PIP as the App Store for Python.
- Python comes with some built-in apps (Standard Library).
- But if you want to do Data Science (NumPy) or Web Scraping (Requests), you need to download those "apps" from the store using PIP.

✨ Basic Commands

Terminal
# Install a package
pip install requests
 
# Uninstall a package
pip uninstall requests
 
# List installed packages
pip list
 
# Show package details
pip show requests

📜 Requirements Files

It is common practice to list all project dependencies in a requirements.txt file. This allows others to install all necessary packages with a single command.

Terminal
# Create requirements.txt
pip freeze > requirements.txt
 
# Install from requirements.txt
pip install -r requirements.txt

🔍 Finding Packages

You can find thousands of open-source packages on the Python Package Index (PyPI).

💡 Virtual Environments

It is highly recommended to use a virtual environment to keep dependencies required by different projects separate.

Terminal
# Create a virtual environment
python -m venv myenv
 
# Activate (Windows)
myenv\Scripts\activate
 
# Activate (Mac/Linux)
source myenv/bin/activate

✨ Pro Tip: Upgrade PIP

If you get a warning that your PIP version is old, you can upgrade it using:

Terminal
python -m pip install --upgrade pip