What is requirements.txt?
How to Use requirements.txt
Requirements.txt
You started to learn Python. Thought it was a little strange to begin with, but then grown to love its power and its elegance. Then you discovered how good Python libaries are and so easy to get with the pip command. But how do you deploy these to others? Again there is an easy solution.
So you need to understand requirements.txt. You very likely would have heard of it or seen the requirements.txt, and may have even seen this command below. You may need to run pip3 rather than pip if you machine is setup that way.
pip install -r requirements.txt
It doesn’t take long to get proficent at using. Read on to learn the basic rules.
Add as you go along
First important tip of using requirements.txt is not to wait until the end of the project before adding it! As you work on your code you should be adding the libraries that you have used in your code. It is so easy to forget one if you do it at the end. This could leave a production system not starting, or clients getting upset when the code doesn’t work on their system.
So when you download a library say for example the excellent pandas library.
pip install pandas
The installation will hopefully complete successfully. You will get a version number. So at the time of writing it was 1.0.3.
So in the requirements.txt you would add:
pandas==1.0.3
Each new library gets a new line. With a return at the end of each line.
Its simple to read. We have the library name as you used in the pip command. With the version number at the end, with the dots. But then you have the ==, what does this mean?
Well it’s not the only symbol you can use.

Share this post
Twitter
Google+
Reddit
LinkedIn
Email