Skip to content

Instantly share code, notes, and snippets.

@kaniket7209
Created December 3, 2021 20:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaniket7209/9aa972b9d6b5d1542e1731d28de77efc to your computer and use it in GitHub Desktop.
Save kaniket7209/9aa972b9d6b5d1542e1731d28de77efc to your computer and use it in GitHub Desktop.
What is the requirements.txt file?
1. What is requirement file?
Answer: A requirements file is a list of all of a project's dependencies. This includes the dependencies needed by the dependencies. It also contains the specific version of each dependency, specified with a double equals sign ( == ).
Logically, a Requirements file is just a list of pip install arguments placed in a file. Note that you should not rely on the items in the file being installed by pip in any particular order.
2. Why we need requirement.txt?
Answer: It helps us in several ways, even when we revisit our project in the future, as it solves almost all compatibility issues. If you ever work on any Python project or developed any project, you surely know that we usually require several numbers of packages. However, while developing a project, we generally used a particular version of packages. Later on, the package manager or maintainer may make some changes, and these modifications can easily break your entire application. Therefore it is too much work to keep track of every modification in the packages. Specifically, where the project is way too big, it is essential to keep track of each package we are using to avoid unexpected surprises.
One of the standard ways to solve these types of issues is to use a virtual environment. The reason is that there are two main types of packages and locations where the Python libraries usually stored, and we usually do not need all types of these packages while working on a particular project; hence it is required to know which one is required per project to make it easier for the reproducibility.
3. How can we get the requirements.txt file using virtual env?
Answer: To create the requirement.txt file, we can use the following command:-> pip3 freeze > requirements.txt
4. How to Get the Requirements.txt File using Pipenv ?
Answer: You can use the following given instruction to get the requirement.txt file:
a) Type the following command to install the pipenv
-> pip install pipenv
b) Now type the following command and press enter button.
-> pipenv install mypackage (This will install the packages that are required for the projects.)
c) Now to activate the virtual environment, you can use the following commands:
-> pipenv shell OR pipenv run
d) Now type the following command to run the script in the virtual environment.
-> pipenv run Python myscript.py (This command is used to run the specified script in the virtual environment)
e) you can use this pipfile as the alternate to the requirements.txt file. However, if you still want to use the requirements.txt file, you can use the following command:
-> pipenv -r lock >> requirements.txt
5. How to Get the Requirements.txt File: Without Virtualenv using Pipreqs?
Answer: Lets us see how it works:
a) First of all, you have to install the "pipreqs," so to download it type the following given command in the cmd and hit the enter button:
-> pip install pipreqs
b) Once the installation gets completes, you can then start "pipreqs" to get the requirement.txt file by pointing it out to the location where your project folder is located.
-> pipreqs /path/to/project
To verify that the requirement.txt file is successfully created, you can see in your project's folder that a new file "requirement.txt" will be created
6. Is pip same as npm?
Answer: NO, npm is the command-line interface to the npm ecosystem. It is battle-tested, surprisingly flexible, and used by hundreds of thousands of JavaScript developers every day.
On the other hand, pip is detailed as "A package installer for Python". It is the package installer for Python.
1. Choose the correct syntax of requirement file
a) requirement.txt
b) requirements.txt
c) Requirement.txt
d) Reuirements.txt
Answer: b)
2. What does requirements.txt not involves
a) System Packages
b) Site Packages
c) virtualenv
d) modules
Answer: c)
3. Which of the following are requirements in a robots.txt file?
a) *Disallow: [URL string not to be crawled]
b) Allow: [URL string to be crawled]
c) Sitemap: [sitemap URL]
d) *User-agent: [user-agent name]
Answer: b)
4. pip is a
a) API
b) package manager
c) module
d) None of the above
Answer: b)
5. Can we use pip to install modules for JavaScript?
a) yes
b) no
Answer: b)
6. pip is a tool that allows you to install and manage additional libraries and dependencies that are not distributed as part of the standard library.
a) True
b) False
Answer: a)
7. Is pip and npm same?
a) Yes
b) no
Answer: b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment