Concepts / Installing Python and Setting Up Your Environment

Installing Python and Setting Up Your Environment

The Python Package Index (PyPI) is a repository containing thousands of open source Python libraries.

  • Programming

From Shared Code to Local Projects

When a Python project needs functionality that someone has already created, you do not necessarily need to build that functionality from the beginning. Python provides an ecosystem for sharing and reusing code. Two parts are central to this process: the Python Package Index, usually called PyPI, and pip. PyPI is where many open source Python libraries are stored, while pip is the command-line tool used to retrieve and install those libraries on your local machine.

Key point

Remember the basic distinction: PyPI is the repository, and pip is the installation tool.

What PyPI Contains

The Python Package Index is a repository containing thousands of open source Python libraries. In this context, a repository is a storage location where libraries are made available for users to access. PyPI therefore acts as a shared collection: libraries are placed there so Python developers can find and reuse them in their own projects.

PyPIrepositoryOpen source Pythonlibrariesthousands availableA Python libraryexisting codecontainsincludes
What does PyPI contain, and how are Python libraries organized within it?

The Job of pip

pip is a command-line tool used to install libraries from PyPI onto your local machine. When you request a library with pip, pip connects to PyPI, finds the library you requested, downloads it, and installs it on the local machine. This gives pip an active role: it carries out the retrieval and installation, while PyPI provides the place from which the library is retrieved.

Install requestpipinstallation toolConnect to PyPIFind libraryDownload libraryInstall locallylocal machinereceived byusesthenthenthen
What does pip do when it receives a request to install a Python library?

Following a Library into Your Environment

Worked example

A hypothetical library request

Suppose a Python project needs an existing open source library that is available through PyPI. What happens when you use pip to install it?

  1. 1
    1. Make the request

    You use pip to request the library. pip is the command-line installation tool.

  2. 2
    2. Reach the repository

    pip connects to PyPI, the repository containing the available Python libraries.

  3. 3
    3. Locate and retrieve

    pip finds the requested library in PyPI and downloads it.

  4. 4
    4. Place it locally

    pip installs the downloaded library on your local machine, making the library available within the local Python environment.

Result

The library moves from its shared storage location on PyPI into the local environment through pip. PyPI supplies the library; pip performs the retrieval and installation.

Library requestpipretrieves and installsPyPIlibrary repositoryPython librarydownloaded codeLocal Pythonenvironmentinstalled librarysent toqueriesprovidesretrieved byinstalls into
How does a library move from PyPI to your Python environment when you use pip?

The important change in this workflow is the library's location. Before installation, the library is available through the shared repository, PyPI. After pip completes the process, the library has been installed on your local machine. The repository and the local environment are different places, and pip connects them.

Keeping the Two Roles Separate

  • Common mistake

    Treating PyPI and pip as the same thing.

    What it looks like

    Saying that PyPI installs a library or that pip is the repository.

    Why it fails

    PyPI stores and provides access to libraries, while pip is the command-line tool that retrieves and installs them.

    Do this instead

    Use the short reminder: PyPI stores; pip installs.

  • Common mistake

    Thinking that finding a library on PyPI automatically places it on your computer.

    What it looks like

    Assuming that a library is already part of the local Python environment because it exists in PyPI.

    Why it fails

    The source distinguishes the repository from the local installation. pip performs the step that downloads and installs the library locally.

    Do this instead

    Trace the complete workflow: pip connects to PyPI, finds the library, downloads it, and installs it on the local machine.

  • Common mistake

    Planning to recreate functionality that an existing library already provides.

    What it looks like

    Beginning a project by rebuilding code that could be reused from an available open source library.

    Why it fails

    Using PyPI and pip helps developers avoid reinventing the wheel and leverage existing, tested code.

    Do this instead

    First consider whether an appropriate library is already available through PyPI.

PartRoleLocation or action
PyPIStores and provides access to librariesShared repository
pipRetrieves and installs librariesCommand-line tool
Local Python environmentReceives the installed libraryYour local machine

The three parts of the basic library installation workflow

Check Your Understanding

EASY

A teammate says, “I found the library on PyPI, so it is already installed locally.” Explain what part of the workflow is missing and identify which tool performs it.

Hints
  • Separate the repository from the installation tool.
  • Recall the sequence involving finding, downloading, and installing.
Key point

A complete answer should say that PyPI is the repository, but the library must still be retrieved and installed locally by pip.

The Installation Model

  1. 1
    PyPI is a repository containing thousands of open source Python libraries.
  2. 2
    pip is a command-line tool used to install libraries from PyPI onto your local machine.
  3. 3
    PyPI stores the libraries, while pip retrieves and installs them.
  4. 4
    The workflow is: request a library with pip, connect to PyPI, find and download the library, then install it locally.
  5. 5
    Using this ecosystem lets developers reuse existing, tested code instead of reinventing the wheel.

Key Takeaways

  • PyPI is the shared repository for thousands of open source Python libraries.
  • pip is the command-line installation tool that retrieves libraries from PyPI.
  • PyPI and pip have different roles: PyPI stores libraries, and pip installs them locally.
  • The basic workflow moves a requested library from PyPI through pip into the local Python environment.
  • Together, PyPI and pip support code sharing, reuse, and avoiding unnecessary reinvention.

More concepts starting with I