How to determine packages used in a Python project that has no requirements.txt
Python projects that do not come with a requirements.txt can be a nightmare to work with. Luckily, there is a solution

Search for a command to run...
Python projects that do not come with a requirements.txt can be a nightmare to work with. Luckily, there is a solution

No comments yet. Be the first to comment.
This series focuses on handy tricks I'm discovering as I code along. Those hidden gem packages that you'll only find out when you face specific kinds of challenges.
Convert sheng to shembeteng using nodejs.
Share files from Linux to Windows

Are you tired of waiting forever for large files to download on Linux? The terminal has some powerful tools that can help you maximize your bandwidth.

In Linux, an alias is a command that executes another command or series of commands using a different name. Aliases are typically used to make it easier to run frequently used or complex commands by typing a shorter, easier-to-remember version. The a...

This blog post explores the benefits of microservices in building a scalable and maintainable application.

Convert sheng to shembeteng using nodejs.

Have you ever cloned a python project on GitHub that did not include a requirements.txt and you could not make it run on your local machine due to compatibility issues? What if there was a solution that could crawl the whole project and generate a requirements.txt file for you for the packages used and their versions? Well, good news there is!
You need to have python 3.5+ installed - Download python here
Pip package installer- Download pip from here
Venv for creating virtual environments - Download Venv from here
I came across this issue when I was following machine learning tutorials on Microsft Learn. The GitHub repo only has the code with no requirements.txt. I was particularly interested in the code for extracting text from images and pdfs. The code looks as shown in the image below.

You can see there is no requirements.txt. We have to first clone the whole repo then navigate to the specific folder we want to work on

Start by cloning the whole repository.
git clone https://github.com/MicrosoftLearning/AI-102-AIEngineer.git
Then get into the specific folder we are interested in
cd AI-102-AIEngineer-master\20-ocr\Python\read-text\
The project structure is as shown below ``` AI-102-AIEngineer-master └───20-ocr | └───Python | | └───read-text | | | read-text.py | | | .env | | └───images | | | | Lincoln.jpg | | | | Note.jpg | | | | Rome.pdf
## Setting up an environment
Setting up an environment for a project ensures that the installs done for the project are within that environment without affecting global installs. This can also be useful when a specific package is only installed once on a specific project.
To set up a venv environment:
```shell
python -m venv name-of-environment
Name the environment folder that you wish. I'll name mine venv. My current folder structure now looks like ``` AI-102-AIEngineer-master └───20-ocr | └───Python | | └───read-text | | | read-text.py | | | .env | | | venv | | └───images | | | | Lincoln.jpg | | | | Note.jpg | | | | Rome.pdf
On windows activate the environment
```shell
cd venv\Scripts\ && activate && cd .. && cd ..
With the environment set, next, we need to install (Pigar)[https://pypi.org/project/pigar/]. Pigar is a tool used to generate requirements.txt for python projects. Install Pigar with pip
pip install pigar
To use pigar on our project simply run
pigar
You can find a generated requirements.txt on your project folder. Learn more about pigar from its documentation. With a requirements.txt, install all the dependencies using
pip install -r requirements.txt
Happy hacking!