Third-Party Libraries
A third-party package is code that is not part of Python's standard library. You install it separately. The Python Package Index, called PyPI, is the main public place to get these packages.
On your own computer, create a virtual environment for each project. This is a separate folder for the project's installed packages, so one project's packages do not affect another's. Then install packages with python -m pip. The last lesson of the course shows the commands. A requirements file lists the package versions a project needs, like this:
tabulate==0.9.0
To install everything in the file, run:
python -m pip install -r requirements.txt
Once a package is installed, you import it like any other module:
from tabulate import tabulate
rows = [["Notebook", 4], ["Pen", 12]]
print(tabulate(rows, headers=["item", "quantity"]))
Output:
item quantity
-------- ----------
Notebook 4
Pen 12
Writing an exact version, like ==0.9.0, is called pinning. It lets your teammates, and the servers that run your code, set up the same packages you have. Only add a package when it saves you real work, and when it is well maintained and documented.
The exercise already has its requirements file. Complete the table data and the tabulate call.