Third-party libraries and pip
You need to call someone else's API, parse a web page, or analyze a table with a million rows. The standard library has some of this, but the community has written far handier tools: requests, beautifulsoup4, pandas, and thousands more. These are third-party libraries — what isn't part of Python's distribution and is installed separately with pip, the standard package manager.
What are third-party libraries?
What is pip?
Installing and using pip
Usually pip is already installed along with Python. You can check the presence and version of pip like this:
pip --version
Expected result:
pip 23.1.2 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)
Basic pip commands
Installing a package
pip install requests
Expected result:
Collecting requests Downloading requests-2.31.0-py3-none-any.whl (62 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 kB 1.2 MB/s eta 0:00:00 Installing collected packages: requests Successfully installed requests-2.31.0
Installing a specific version
pip install requests==2.25.1
Expected result:
Collecting requests==2.25.1 Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 kB 1.8 MB/s eta 0:00:00 Installing collected packages: requests Successfully installed requests-2.25.1
List of installed packages
pip list
Expected result:
Package Version ---------- --------- certifi 2023.5.7 charset-normalizer 3.1.0 idna 3.4 pip 23.1.2 requests 2.31.0 setuptools 67.8.0 urllib3 2.0.3
Removing a package
pip uninstall requests -y
Expected result:
Found existing installation: requests 2.31.0 Uninstalling requests-2.31.0: Successfully uninstalled requests-2.31.0
Popular third-party libraries
Python has a huge number of third-party libraries for a wide variety of tasks. Here are some of the most popular and useful:
The choice of library depends on the specific task you want to solve. The Python community is very active, and ready-made solutions already exist for most practical tasks, which can be installed via pip.
Example of installing a popular library:
# Installing pandas for data analysis pip install pandas # Installing Flask for web development pip install flask
Virtual environments
If you install every library into your system Python, sooner or later you'll hit a conflict: one project needs django 3.0, another needs django 4.2, but only one version can be installed. The standard practice is to create a separate virtual environment for each project.

Creating a virtual environment
# Creating a virtual environment python -m venv myenv # Activating the virtual environment # On Windows: myenv\Scripts\activate # On macOS/Linux: source myenv/bin/activate # After activation, the environment name will appear at the beginning of the command prompt (myenv) $
Installing packages in a virtual environment
# Installing packages in the activated virtual environment pip install pandas matplotlib
Saving and installing dependencies
# Saving the list of installed packages pip freeze > requirements.txt # The contents of the requirements.txt file will look something like this: # matplotlib==3.7.2 # numpy==1.25.2 # pandas==2.0.3 # ... # Installing packages from the requirements.txt file pip install -r requirements.txt
Understanding Check
Which command will correctly install pandas version 1.5.0?
