Content · Programming · Python

Python pip freeze vs Dependency Declarations

pip freeze lists currently installed distributions and exact versions; it does not distinguish direct project dependencies from packages installed only as transitive requirements.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

This guide explains pip freeze vs dependency declarations through a focused Python example. You will learn the behavior to expect, why it matters in a real program, and how to recognize the common mistakes before applying it in your own project.

What You Will Learn


pip freeze lists currently installed distributions and exact versions; it does not distinguish direct project dependencies from packages installed only as transitive requirements.

When and Why to Use It


The following example focuses on a practical use of pip freeze vs Dependency Declarations.

Step-by-Step Example


# In the project virtual environment:
# python -m pip freeze
# python -m pip list

requirements = {"requests": ">=2.31,<3", "rich": ">=13,<15"}
print(sorted(requirements))

Understanding the Example


The dictionary represents two intentional top-level requirements. A full freeze can contain many more package names from dependency resolution.

Expected Output


['requests', 'rich']

Important Behavior and Edge Cases


Do not automatically paste the entire global environment freeze into a reusable project’s declared dependencies.

Try It Yourself


Compare the output of pip freeze with only the packages your application imports directly.

Run environment-management commands in your terminal, not in a Python source file. Use the executable associated with the selected project interpreter and verify the environment before installing dependencies.

Common Beginner Mistakes


  • Do not automatically paste the entire global environment freeze into a reusable project’s declared dependencies.
  • Running installation commands against a different Python interpreter than the one used for the project.
  • Skipping the practice step and assuming the example covers every input. Test at least one normal case and one edge case relevant to this topic.

Key Takeaways


  • pip freeze lists currently installed distributions and exact versions; it does not distinguish direct project dependencies from packages installed only as transitive requirements.
  • The dictionary represents two intentional top-level requirements.
  • Apply the technique deliberately, checking its documented input requirements and failure behavior before integrating it into a larger project.
Share this resourceSend this page to someone who may find it useful.