Generate requirements.txt for your Python project on the fly

Akhilesh Mishra
5 min readJul 10, 2024

As a DevOps engineer, I frequently collaborate with multiple teams, diving into various projects and repositories. One common challenge I face is encountering Python code without a requirements.txt file.

Every time I run such code, I need to figure out and manually install the necessary dependencies. I found it a waste of time and effort. I am sure you guys also feel the same way.

So I dug around, did some Google searches, experimented with a few tools, and found many good ones.

My favorites are pipreqs and pigar. In this blog post, I will show you how to use these tools, and how to generate requirements.txt for your Python project on the fly.

Photo by Mika Baumeister on Unsplash

Read my other posts on Python

Some people might ask — Why not pip freeze?

pip freeze only saves the packages that are installed with pip install in your environment.

pip freeze saves all packages in the environment including those that you don't use in your current project (if you don't have virtualenv).

and sometimes you just need to create requirements.txt

--

--

Akhilesh Mishra

DevOps engineer with expertise in multi-cloud, and various DevOps tools.