Skip to Main Content

Python in Digital Scholarship

This guide will provide an introduction to using Python in research and instruction and what resources are available in the Freedman Center.

Finding and Installing Packages

Python’s functionality is extended through the use of packages—reusable modules of code that can be installed from the Python Package Index (PyPI). These packages provide tools for data analysis, web scraping, machine learning, and countless other tasks relevant to research and instruction.

Tools for Package Management

  • pip – The standard Python package installer, used to install and manage packages from PyPI.

  • venv – Used to create isolated environments where packages can be installed without affecting the system-wide Python.

  • conda – An alternative package and environment manager included with the Anaconda distribution (useful for managing scientific libraries and non-Python dependencies).

Finding Packages

To search for packages:

  • Browse https://pypi.org by keyword or category.

  • Use the command line:

    pip search [package-name]  # Deprecated, consider browsing PyPI instead
    

Installing a Package

Use pip install inside an activated virtual environment:

pip install pandas

To install a specific version:

pip install pandas==1.5.3

To install multiple packages from a requirements.txt file:

pip install -r requirements.txt

Viewing Installed Packages

To list installed packages:

pip list

To see details about a specific package:

pip show pandas

Upgrading or Uninstalling

pip install --upgrade numpy
pip uninstall matplotlib

Best Practices

  • Always install packages inside a virtual environment to avoid dependency conflicts.  This allows collaborators or future users to recreate the same environment.

  • Use requirements.txt to document dependencies for reproducibility:

pip freeze > requirements.txt