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.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay