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?
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 -
- At first create virtual environment -
- Then active environment -
- Now create
requirements.infile and then write in it only 'django'.
- Now write
pip-compile requirements.inand hit enter. Then you will find a
# # 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.
Top comments (0)