Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically create requirements.txt

Sometimes I download the python source code from github and don't know how to install all the dependencies. If there is no requirements.txt file I have to create it by hands.
The question is:
Given the python source code directory is it possible to create requirements.txt automatically from the import section?

like image 849
Igor Barinov Avatar asked Jul 28 '15 18:07

Igor Barinov


People also ask

Does requirements txt update automatically?

txt file and it will auto update all your high-level packages to the latest versions, keeping your original formatting and comments in-place. For example, running pur on the example requirements. txt updates the packages to the currently available latest versions: $ pur -r requirements.

What is Requirements txt in Python?

In Python requirement. txt file is a type of file that usually stores information about all the libraries, modules, and packages in itself that are used while developing a particular project. It also stores all files and packages on which that project is dependent or requires to run. Typically this file "requirement.

How do I create a requirements txt Jupyter notebook?

Simply open a terminal and navigate to the folder you want your requirements file to be in. You can then activate a virtual environment using venv or conda. It will take every package you have installed on that environment.


1 Answers

You can use the following code to generate a requirements.txt file:

pip install pipreqs  pipreqs /path/to/project 

more info related to pipreqs can be found here.

Sometimes you come across pip freeze, but this saves all packages in the environment including those that you don't use in your current project.

like image 163
DJanssens Avatar answered Oct 16 '22 07:10

DJanssens