Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Managing Python dependencies with the Thoth JupyterLab extension

March 19, 2021
Francesco Murdaca
Related topics:
Artificial intelligenceMicroservicesOpen sourcePython
Related products:
Red Hat Enterprise Linux

    JupyterLab is a flexible and powerful tool for working with Jupyter notebooks. Its interactive user interface (UI) lets you use terminals, text editors, file browsers, and other components alongside your Jupyter notebook. JupyterLab 3.0 was released in January 2021.

    Project Thoth develops open source tools that enhance the day-to-day lives of developers and data scientists. Thoth uses machine-generated knowledge to boost your applications' performance, security, and quality through reinforcement learning with artificial intelligence. (Watch this video to learn more about resolving dependencies with reinforcement learning.)

    This machine learning approach is implemented in Thoth adviser, a recommendation engine for Python applications. Thoth integrations use this knowledge to provide software stack recommendations based on user inputs.

    This article introduces you to jupyterlab-requirements, a JupyterLab extension for managing and optimizing Python dependencies in your Jupyter notebooks. As you will learn, using the jupyterlab-requirements extension is a smart and easy way to ensure that your code and experiments are always reproducible.

    Making application dependencies reproducible

    When creating code or conducting experiments, reproducibility is an important requirement. Ensuring that others can rerun experiments in the same environment the creator used is critical, especially when developing machine learning applications.

    Let’s consider one of the first steps for developing an application: specifying dependencies. For example, your project might depend on pandas for data exploration and manipulation or TensorFlow for training a model.

    One approach to this task is to run a command in the notebook cell to install the dependencies directly on the host, as shown in Figure 1. This way, the next user can run the same cell and install similar packages.

    A user installing dependencies in the notebook cell using the pip install command.

    Another potential strategy is to provide a requirements.txt file that lists all of the dependencies so that someone else can install them before starting the notebook. Figure 2 shows an example.

    A sample list of software dependencies in a text file.
    Figure 2: A sample list of dependencies.

    Do you see any issues with these two approaches to specifying dependencies?

    Neither one supports reproducibility!

    In the first scenario, let's say another user tried to rerun the same cell sometime after a new version of the library was released. They might experience different behavior from the initial notebook output.

    The same issue can arise with the requirements.txt file, only with the package names. Even if you stated the direct dependencies with the exact version number, each of those dependencies might depend on other so-called transitive dependencies that are also installed.

    To guarantee reproducibility, you must account for all dependencies with specific version numbers for direct and transitive dependencies, including all hashes used to verify the provenance of the packages for security reasons (check these docs to learn more about security in software stacks). To be even more precise, the Python version, operating system, and hardware all influence the code’s behavior. You should share all of this information so other users can experience the same behavior and obtain similar results.

    Project Thoth aims to help you specify direct and transitive dependencies so that your applications are always reproducible and you can focus on more pressing challenges.

    Dependency management with jupyterlab-requirements

    The Thoth team has introduced jupyterlab-requirements, a JupyterLab extension for dependency management that is currently focused on the Python ecosystem. This extension lets you manage your project's dependencies directly from a Jupyter notebook, as shown in Figure 3.

    Screenshot of the jupyterlab-requirements extension with the Managed Dependencies menu item highlighted.
    Figure 3: Managing dependencies in JupyterLab.

    When you click Manage Dependencies, you will see the dialog box shown in Figure 4.

    A dialog box stating ‘No dependencies found! Click button above to add new packages.’
    Figure 4: A new notebook with no dependencies identified.

    Initially, the extension will not identify any dependencies when you start a new notebook; it checks the notebook metadata to detect them. You can add your packages by clicking the button with the plus-sign (+) icon, as shown in Figure 5.

    Screenshot of the Manage Dependencies screen with the option to add new package dependencies.
    Figure 5: Adding new packages with the jupyterlab-requirements extension.

    After saving, an Install button will appear. You can check the package names and versions before installing the dependencies, as shown in Figure 6.

    Screenshot of the Manage Dependencies screen with the Install button and sample packages added.
    Figure 6: The Manage Dependencies screen with sample packages added and ready to install.

    After clicking Install, you will see the screen shown in Figure 7.

    Screenshot of the Manage Dependencies screen with requirements locked, saved, and installed.
    Figure 7: The packages are locked, saved, and installed in the notebook metadata.

    All dependencies—both direct and transitive—will be locked, saved in the notebook metadata, and installed. What’s more, the extension automatically creates and sets the kernel for your notebook. No human intervention is necessary, and you are ready to work on your project.

    Managing dependencies in an existing notebook

    If you have existing notebooks with code, you can still use the jupyterlab-requirements extension to share them. The invectio library analyzes code in the notebook and suggests libraries that must be installed to run the notebook. Figure 8 shows an example.

    There are no dependencies in the notebook metadata, but the extension identifies three packages to be installed.

    Once again, you can just install the dependencies and start working on your project.

    Locking dependencies with Thoth or Pipenv

    The resolution engine you use to lock dependencies provides two files: a Pipfile and a Pipfile.lock. The Pipfile.lock file states all direct and transitive project dependencies with specific versions and hashes. The notebook metadata stores these files and information about the Python version, operating system, and hardware detected. This way, anyone using the same notebook can re-create the environment that the original developer used.

    Two resolution engines are available at the moment: Thoth and Pipenv.

    Currently, Thoth is used by default, with Pipenv as a backup. This setup guarantees that the user will receive the software stack to work on their projects. In the future, users will be able to select a specific resolution engine.

    Using the Thoth resolution engine, you can request an optimized software stack that satisfies your requirements from the Thoth recommendation system. You can choose from the following recommendation types according to your particular needs:

    • Latest
    • Performance
    • Security
    • Stable
    • Testing

    For more information about the various recommendation types, visit the Project Thoth website.

    Note: The notebook metadata stores which resolution engine was used so that anyone can immediately see which one was used to resolve dependencies.

    Configuring the runtime environment

    You don’t need to worry about the runtime environment when using the Thoth resolution engine. Thoth automatically identifies the information needed to generate a recommendation and creates a Thoth configuration file containing the following parameters:

    host: {THOTH_SERVICE_HOST}
    tls_verify: true
    requirements_format: {requirements_format}
    
    runtime_environments:
      - name: '{os_name}:{os_version}'
        operating_system:
          name: {os_name}
          version: '{os_version}'
        hardware:
          cpu_family: {cpu_family}
          cpu_model: {cpu_model}
          gpu_model: {gpu_model}
        python_version: '{python_version}'
        cuda_version: {cuda_version}
        recommendation_type: stable
        platform: '{platform}'

    Note: If you use the Thoth resolution engine, the notebook metadata will also contain information about the runtime environment used for the notebook. In this way, other data scientists using the notebook will be warned about using a different one.

    Installing dependencies and creating the kernel

    Once a lock file is created using either Thoth or Pipenv, the micropipenv tool installs the dependencies in the virtual environment. The micropipenv tool supports dependency management in Python and beyond ("one library to rule them all").

    Once all of the dependencies are installed in your kernel, you are ready to work on your notebook.

    You can choose the name of the new kernel and select the requirements from the drop-down menu. Once everything is installed, the kernel is assigned to the current notebook automatically.

    Conclusion

    The jupyterlab-requirements extension is an open source project maintained by the Thoth team. We are currently exploring new features for the UI, and we welcome anyone who would like to contribute or give us feedback about the extension.

    Have a look at the open issues and get in touch with the team if you like the project or if you find any issues with the extension. The Thoth team also has a public channel where you can ask questions about the project. We are always happy to collaborate with the community on any of our repositories.

    Last updated: February 5, 2024

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.