Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

requirements.txt in python package

I'm studying packages, and I have a question on creating a requirements.txt file.

If a module is imported from python, does it need to be mentioned in the requirements.txt file or can be left out?

I know that for separate modules, they need to be pip installed. For those modules that need to be pip installed, should they be written in the requirements.txt file as 'pip install modulename'?

like image 817
song0089 Avatar asked Dec 29 '18 10:12

song0089


People also ask

How do I install a package using requirements txt in Python?

Use the pip install -r requirements. txt command to install all of the Python modules and packages listed in your requirements. txt file.

What is Requirements txt in pip?

The recommended approach is to use a requirements. txt file (readthedocs.org) that contains a list of commands for pip that installs the required versions of dependent packages. The most common command is pip freeze > requirements. txt , which records an environment's current package list into requirements.

Should I use requirements txt or setup py?

The short answer is that requirements. txt is for listing package requirements only. setup.py on the other hand is more like an installation script. If you don't plan on installing the python code, typically you would only need requirements.


1 Answers

The requirements.txt is a file where one specifies dependencies. For example your program can have dependency on Django or we can say the requirements.txt file in a django project describes the packages that needs to be installed for successfully running a project.

Talking about the sub-modules: Suppose you have specified django in the requirements.txt file, now you don't need to specify any sub-modules (like 'django.shortcuts') in the requirements.txt file. Because they are already included in the django module.

Now one can easily use

from django.shortcuts import path

in your .py files.

Now for separate modules (like pillow) that need to be specified in the requirements.txt file, you don't need to write

pip install pillow

You can just write pillow in a separate line with other modules like:

django

pillow

You can also use the below command to do so:

pip freeze > file_name

In your case file_name will be requirements.txt. This will add all the third-party module names in the requirements.txt file.

like image 151
Shubham Paliwal Avatar answered Sep 30 '22 15:09

Shubham Paliwal