Installing a third-party library with pip

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Installing a third-party library with pip

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which command installs the third-party library requests?
A pip install requests
B import requests install
2. True or false: you must run pip install before you can import a third-party library that is not yet on your computer.
A True
B False
3. Where do you type the pip install command?
A Inside your .py file as a line of Python code
B In the terminal or command prompt
4. Which order is correct for using the requests library for the first time?
A pip install requests, then import requests in the program
B import requests in the program, then pip install requests
5. Which command installs version 2.31.0 of requests?
A pip install requests@2.31.0
B pip install requests==2.31.0

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1pip install requests Apip install requests import requests
2pip install requests==2.31.0 Bpip show requests
3Install a third-party library first, then bring it into a program with import CThe import comes before the install. The library must be installed with pip first, or import fails with ModuleNotFoundError.
4You can check which version of a library is installed DInstalls version 2.31.0 of the requests library instead of the latest version
5import requests pip install requests EDownloads the third-party requests library so a Python program can import it
6pip install requests=2.31.0 FA version number needs two equals signs (==). A single = is not valid pip syntax.

Definitions

pip install requests

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
pip _______ requests
2.
pip install ________ import requests
3.
pip install requests__2.31.0
4.
___ install requests
5.
pip install requests ______ requests

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A # In the terminal:
B pip requests install
C # In the .py file:
D import requests
Question 2
A # Terminal
B pip install requests
C # Python file
D install requests
E print(requests.__version__)
Question 3
A # Terminal
B # Pick a version
C pip install requests=2.31.0
Question 4
A # Terminal
B pip install pyjokes
C # Python file
D import pyjoke
E print(pyjokes.get_joke())
Question 5
A pip install pillow
B # Python file
C from pillow import Image

Answer Key

Installing a third-party library with pip
Section A: Quick Questions
Q1
A — pip install requests
Q2
A — True
Q3
B — In the terminal or command prompt
Q4
A — pip install requests, then import requests in the program
Q5
B — pip install requests==2.31.0
Section B: Match the Pairs
Q1
pip install requests → Downloads the third-party requests library so a Python program can import it
Q2
pip install requests==2.31.0 → Installs version 2.31.0 of the requests library instead of the latest version
Q3
Install a third-party library first, then bring it into a program with import → pip install requests import requests
Q4
You can check which version of a library is installed → pip show requests
Q5
import requests pip install requests → The import comes before the install. The library must be installed with pip first, or import fails with ModuleNotFoundError.
Q6
pip install requests=2.31.0 → A version number needs two equals signs (==). A single = is not valid pip syntax.
Section C: Definitions
Q1
pip install requests — A terminal command that uses pip to download a third-party library (here requests) so a Python program can then import it. Add ==2.31.0 after the name to pick a version.
Section D: Fill in the Blanks
Q1
pip install requests
Q2
pip install requests import requests
Q3
pip install requests==2.31.0
Q4
pip install requests
Q5
pip install requests import requests
Section E: Spot the Error
Q1
B — The pip command order is wrong. The install keyword comes before the library name: pip install requests.
Q2
D — Python code uses the import keyword to load a library after it has been installed. install is a pip command, not Python. It should be: import requests.
Q3
C — A version is chosen with a double equals sign (==) after the library name. A single = is not valid. It should be: pip install requests==2.31.0.
Q4
D — The library name is spelled wrong. The library installed was pyjokes, so the import must match: import pyjokes.
Q5
C — Some libraries are installed under one name but imported under another. pip install pillow is imported as PIL, so the line should be: from PIL import Image.