DEV Community

Cover image for Do not use `pip freeze`
Sajidur Rahman Shajib
Sajidur Rahman Shajib

Posted on

10 1

Do not use `pip freeze`

We are using pip freeze or pip3 freeze command for making requirements.txt for our python projects. We use pip freeze > requirements.txt right?

But when we try to install our project to another machine that time we use pip install -r requirements.txt command to install those packages which we need for that project. But most of the time we face an error which is - version not satisfied.

At first, let's try to understand what freeze actually is for.

"pip freeze is a very useful command, because it tells you which modules you've installed with pip install and the versions of these modules that you are currently have installed on your computer. In Python, there's a lot of things that may be incompatible, such as certain modules being incompatible with other modules."

So if we use pip freeze to make requirements.txt which list we found those all dependencies we don't need our single project. And in that list we don't know which module is compatible and which is incompatible.

So what should be a better approach?

Use pip-compile command. This command makes requirements.txt with which dependencies only you need.

For this command at first install pip install pip-tools

Suppose you want install a django project so what should you do -

  1. At first create virtual environment - python-venv env
  2. Then active environment - source env/bin/activate
  3. Now create requirements.in file and then write in it only 'django'.
  4. Now write pip-compile requirements.in and hit enter. Then you will find a requirements.txt like -
#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
#
#    pip-compile requirements.in
#
asgiref==3.5.0
    # via django
backports-zoneinfo==0.2.1
    # via django
django==4.0.2
    # via -r requirements.in
sqlparse==0.4.2
    # via django

Enter fullscreen mode Exit fullscreen mode

Now you are ready to install your Django. Just write pip install -r requirements.txt and hit enter.

With exact dependencies and comments requirements.txt ready use. So now no unnecessary dependency related issues.

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more