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…


This content originally appeared on DEV Community and was authored by Sajidur Rahman Shajib

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 try to understand which is actually freeze 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

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.


This content originally appeared on DEV Community and was authored by Sajidur Rahman Shajib


Print Share Comment Cite Upload Translate Updates
APA

Sajidur Rahman Shajib | Sciencx (2022-02-10T14:23:32+00:00) Do not use `pip freeze`. Retrieved from https://www.scien.cx/2022/02/10/do-not-use-pip-freeze/

MLA
" » Do not use `pip freeze`." Sajidur Rahman Shajib | Sciencx - Thursday February 10, 2022, https://www.scien.cx/2022/02/10/do-not-use-pip-freeze/
HARVARD
Sajidur Rahman Shajib | Sciencx Thursday February 10, 2022 » Do not use `pip freeze`., viewed ,<https://www.scien.cx/2022/02/10/do-not-use-pip-freeze/>
VANCOUVER
Sajidur Rahman Shajib | Sciencx - » Do not use `pip freeze`. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/10/do-not-use-pip-freeze/
CHICAGO
" » Do not use `pip freeze`." Sajidur Rahman Shajib | Sciencx - Accessed . https://www.scien.cx/2022/02/10/do-not-use-pip-freeze/
IEEE
" » Do not use `pip freeze`." Sajidur Rahman Shajib | Sciencx [Online]. Available: https://www.scien.cx/2022/02/10/do-not-use-pip-freeze/. [Accessed: ]
rf:citation
» Do not use `pip freeze` | Sajidur Rahman Shajib | Sciencx | https://www.scien.cx/2022/02/10/do-not-use-pip-freeze/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.