Python pip

These tasks are about using pip in code or command line and understanding how to install, list, upgrade, and use packages safely.


📦 Python pip – 20 Basic Assignments


1) Check pip Version

In a Python script or terminal, use a command to print the current pip version.

Example (terminal):

pip --version

2) List Installed Packages

Use pip to list all installed packages.

Expected command:

pip list

3) Search for a Package

Use pip to search for a package like requests.

Example:


4) Install a Package

Install the requests package using pip from the command line.


5) Uninstall a Package

Uninstall a package you installed (e.g., requests) using pip.


6) Show Package Information

Use pip show to display information about an installed package (e.g., requests).


7) Install Specific Version

Install a specific version of a package (like requests==2.25.1).


8) Upgrade a Package

Upgrade a package to the latest version using pip (e.g.,:

)


9) Use Installed Package in Script

Write a Python program that imports requests (or another installed package) and prints a simple result, e.g. version.


10) Create requirements.txt

Generate a requirements.txt file listing all installed packages.

Example:


11) Install from requirements.txt

Provide a requirements.txt and install packages from it using:


12) Check if Package is Installed

Write a Python script that tries to import a package and prints whether it’s installed:


13) Uninstall All From Requirements

Uninstall all packages listed in a requirements.txt using pip (combine list + uninstall logic).


14) Create a Virtual Environment

Create a Python virtual environment using python -m venv env and activate it, then install a package inside it.


15) Deactivate Virtual Environment

Practice deactivating a virtual environment and verify imports fail when outside.


16) Install a Testing Package

Install a package for testing like pytest and verify it installs.


17) List Outdated Packages

Use pip to show only outdated packages:


18) Upgrade All Outdated Packages

Use pip to upgrade all outdated packages one at a time.


19) Install a Package With Extras

Install a package with optional extras (e.g., requests[security]), if available.


20) Fix Broken Installation

Practice uninstalling and reinstalling a package that produces an import error.


🧠 What You’re Practicing

Concept
Example

Check pip version

pip --version

List installed packages

pip list

Install package

pip install pkgname

Uninstall package

pip uninstall pkgname

Show package info

pip show requests

Install specific version

pip install pkg==1.0.0

Upgrade package

pip install --upgrade pkg

Use requirements files

pip install -r requirements.txt

Use virtual environment

python -m venv env


⚠️ Notes for Beginners

✔ Commands like pip install … run in the terminal / command prompt, not inside Python scripts. ✔ Virtual environments help you install packages without affecting the global Python setup. ✔ Using requirements.txt is important when sharing projects.


📌 Example Exercise

Install and use a real package

  1. Run:

  1. Write a Python script:

  1. Run it and observe ASCII output.


canvil: 333f6c7d-6876-4f7e-b6ad-1bdb2233f5c1

Last updated