Python Libraries

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Libraries

One factor behind Python’s success is its vast collection of libraries, especially for scientific computing, data analysis, and machine learning. The availability and wide selection of pre-made, often production-ready, code that can easily be incorporated into projects have helped speed up the development process. Python’s active communities have helped ensure that its libraries are well-maintained, regularly updated, and documented.

Modules, Packages, and Libraries

Python programmers often use the terms modules, packages, and libraries interchangeably. Each actually refers to something different; only two have a technical definition in Python:

Importing Modules and Packages

Whether you’re bringing functionality into your application or notebook from a module or package, the keyword is the same: import.

Using the Python Standard Library

After looking at the previous examples, you probably wonder, “Where did math come from?”

Using PyPI, the Python Package Index

Python has a centralized official directory where developers can find and distribute modules and packages: PyPI, the Python Package Index.

Using pip, the Python Package Installer

pip is Python’s standard package management system, which helps you install and manage libraries that are not part of the Python Standard Library. It’s a command-line tool you’ll often use as a Python developer.

Installing Packages

To install a package listed on PyPI with pip, use the following code on the command line:

Confirming a Package Is Installed

The simplest way to confirm that a package is installed is to use pip show:

Installing Multiple Packages With requirements.txt

Many projects import functionality from multiple packages, so pip can also import multiple packages whose names are listed in a requirements.txt file. The following command makes pip install all the packages listed in requirements.txt:

Listing Installed Packages

To see which packages are installed, use this command:

Upgrading Packages

If you found some out-of-date packages while running pip list --outofdate, you can upgrade them using the --upgrade flag. Here’s a command to upgrade a package named package_name:

Uninstalling Packages

To uninstall a specific package, use pip uninstall:

See forum comments
Download course materials from Github
Previous: Introduction Next: Python Libraries Demo