Python PIP


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


🔹 What is PIP?

PIP stands for Pip Installs Packages. It is used to install Python packages from PyPI (Python Package Index).


🔹 Check if PIP is Installed

You can check if PIP is already installed by running this command in your terminal or command prompt:

pip --version

✅ Output example:
pip 24.0 from ... (python 3.x)


🔹 Install a Package

Use the following command to install any Python package:

pip install package-name

Example:

pip install requests

🔹 Use Installed Package

Once installed, you can import and use it in your Python code:

import requests

response = requests.get("https://example.com")
print(response.status_code)

🔹 List All Installed Packages

pip list

✅ This shows all packages currently installed in your Python environment.


🔹 Show Package Info

pip show package-name

Example:

pip show numpy

🔹 Uninstall a Package

pip uninstall package-name

Example:

pip uninstall flask

🔹 Upgrade a Package

pip install --upgrade package-name

Example:

pip install --upgrade pandas

🔹 Requirements File

You can install multiple packages from a file named requirements.txt:

pip install -r requirements.txt

✅ This is commonly used in projects to install all dependencies at once.


Practice Questions

Q1. Write a terminal command to check your current pip version.

Q2. Write a terminal command to install the pandas package using pip.

Q3. Write a Python program to import and use the math package (standard library).

Q4. Write a terminal command to uninstall the flask package from your system.

Q5. Write a terminal command to list all installed packages and check if requests is installed.

Q6. Write a terminal command to show full details of the numpy package using pip show.

Q7. Write a terminal command to upgrade the scikit-learn package to the latest version.

Q8. Write a terminal command to install packages from a requirements.txt file.

Q9. Write a terminal command to try installing a non-existent package and observe the error.

Q10. Write a terminal command to reinstall a broken package using pip.


Go Back Top