Courseiva
Modules and PackagesmediumMultiple ChoiceObjective-mapped

How to Manage Python Dependencies with pip freeze and requirements.txt?

A team uses virtual environments to manage dependencies. They need to ensure that a script runs with the exact same module versions across different environments. Which approach is best?

Quick Answer

The answer is to run pip freeze and store the output in a requirements.txt file, then use pip install -r on other systems. This approach is correct because pip freeze outputs the exact versions of all installed packages in the current environment, and capturing that output into a requirements.txt file creates a snapshot that can be used to reproduce the identical environment elsewhere. On the Certified Associate Python Programmer PCAP exam, this tests your understanding of deterministic dependency management and reproducible builds, a core concept for working with virtual environments. A common trap is confusing pip freeze with pip list, which shows packages but not in a format suitable for installation. Remember the mnemonic: freeze locks the versions, list just looks.

⚠ Common exam trap

Python Institute often tests the misconception that copying the virtual environment folder (Option B) is a valid way to replicate dependencies, but the trap is that virtual environments are not portable across different operating systems or Python versions due to absolute paths and compiled extensions.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Run pip freeze and store the output in a requirements.txt file, then use pip install -r on other systems.

`pip freeze` outputs the exact versions of all installed packages in the current environment, and storing that output in a `requirements.txt` file allows you to reproduce the same environment on another system by running `pip install -r requirements.txt`. This ensures deterministic dependency management across different environments, which is the standard practice for reproducible builds in Python.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Use sys.path.append to add module directories.

    Why it's wrong here

    This is fragile and does not manage versions.

  • Copy the entire virtual environment folder to other systems.

    Why it's wrong here

    Virtual environments are not portable across systems.

  • Include the modules in a __pycache__ directory.

    Why it's wrong here

    __pycache__ stores bytecode, not installable modules.

  • Run pip freeze and store the output in a requirements.txt file, then use pip install -r on other systems.

    Why this is correct

    This is the standard method for replicating environments.

About these practice questions

Courseiva writes every PCAP question from scratch — 169 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on PCAP

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A Python script uses a third-party library 'requests'. The developer wants to ensure that the exact version 2.25.1 is installed in the project's environment. Which tool and command should be used?

easy
  • A.pip install requests
  • B.pip install requests==2.25.1
  • C.pip3 install requests==2.25.1
  • D.pip instll requests==2.25.1

Why B: Both options B and C are correct because they use the standard pip syntax for pinning a specific version: `package==version`. The command `pip install requests==2.25.1` (B) works on systems where `pip` is linked to Python 3, while `pip3 install requests==2.25.1` (C) explicitly invokes the Python 3 version of pip. Both achieve the same result—installing requests exactly version 2.25.1. Option A fails to specify a version, and option D contains a typo ('instll') that will fail.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.