Overview of requirements.txt and Direct GitHub Sources
Last Updated :
27 Jun, 2024
When building a Python project a typical way of handling the dependencies is to add them to a requirements.txt. The 'requirements.txt' is a simple text file, which stores names of the modules and their corresponding versions. A user who wants to execute the project in their own system can simply copy the project and install all the necessary dependencies using a simple command 'pip install -r requirements.txt`
pip install -r requirements.txt
This ensures a developer to inform about all the required modules and ensure a consistent development environment across different systems.
Overview of requirements.txt
The requirements.txt file is a simple text file that lists all the dependencies and their versions required for a project. This helps developers avoid compatibility issues and ensure consistent execution of code.
Importance of Specifying Direct GitHub Sources
In addition to installing packages from the Python Package Index (PyPI), you can also install modules directly from public GitHub repositories. This is particularly useful when a package is not available on PyPI or when you need a specific version or branch of a package that is hosted on GitHub.
Basic Structure of requirements.txt
Common Usage and Format
The requirements.txt file typically the package names and optional version numbers. For example:
numpy==1.20.3
pandas
Specifying GitHub Repositories
In addition to installing packages from PyPI, we can also install modules from public github repositories by adding the a line like this to your `requirements.txt`.
git+https://github.com/<username>/<repository_name>.git@<branch_or_commit(optional)>#egg=<package_name>
where,
- `git+https://github.com/<username>/<repository_name>.git`: public GitHub repository URL with required package
- `@<branch_or_commit`(optional)>`: Indicates the branch, tag, or commit hash you want to install from.
- `#egg=<package_name>`: name of the package, which is required.
Examples:
Example 1: Basic Repository Link
git+https://github.com/psf/requests.git#egg=requests
Example 2: Specifying a Branch
git+https://github.com/psf/requests.git@main#egg=requests
Example 3: Specifying a Tag
git+https://github.com/psf/[email protected]#egg=requests
Installing modules using pip and requirements.txt
To install all the modules required by your project in your development environment, you can follow the below steps:
1. Create a text file and rename it to 'requirements'. The file should look like 'requirements.txt'
2. Add all the modules and versions (optional) you need for your project in the requirements.txt file.
example:
numpy==1.20.3
pandas
3. In addition to installing packages from PyPI, we can also install modules from public github repositories by adding the a line like this to your `requirements.txt`.
git+https://github.com/<username>/<repository_name>.git@<branch_or_commit(optional)>#egg=<package_name
Example:
git+https://github.com/psf/requests.git@main#egg=requests
numpy
4. Proceed to install you packages using the following command:
pip install -r requirements.txt
5. The packages should be successfully installed in your development environment and must be ready to use.
adding dependencies to requirements.txt
installing requests module from gitThus, we have successfully installed a package directly from github source.
Similar Reads
How to Contribute to Open Source Android Projects on GitHub?
Contributing to open-source projects is an excellent way for developers to improve their skills, gain experience, and give back to the community. Android projects on GitHub offer a rich ecosystem where you can collaborate, learn, and make a tangible impact. This guide will walk you through the steps
3 min read
How to Create Requirements.txt File in Python
Creating and maintaining a requirements.txt file is a fundamental best practice for Python development. It ensures that your project's dependencies are well-documented and easily reproducible, making it easier for others to work on your code and reducing the likelihood of compatibility issues. Why U
4 min read
How to Create Requirements in TestLink?
Creating requirements in TestLink is a crucial process for test management and quality assurance. TestLink is a popular open-source test management tool that helps teams define, track, and manage requirements effectively. By establishing clear requirements, you ensure that your testing efforts are a
3 min read
How to Create Pull Request on GitHub Without Using any IDE?
Creating a pull request (PR) on GitHub is an important part of collaborative software development. It allows you to propose changes to a project, which can then be reviewed and merged by other contributors. You don't need an Integrated Development Environment (IDE) to create a pull request. In this
2 min read
How to Contribute to Open Source Projects on GitHub?
Contributing to open-source projects is an excellent way to improve your skills, gain experience, and give back to the developer community. GitHub, the largest platform for open-source collaboration, makes it easy to contribute to projects, whether you're fixing bugs, adding features, or improving d
8 min read
Google Cloud Source Repositories vs GitHub
Google Cloud Source Repositories is a service managed by Google Cloud that allows developers to host and manage Git repositories in the cloud. It offers a platform for version control that is both scalable and secure, making teams work together on software projects better. Integrated with other Goog
11 min read
How to Add Code on GitHub Repository?
GitHub is a powerful platform for hosting and sharing code. Whether youâre working on a solo project or collaborating with others, adding code to a GitHub repository is essential. Hereâs a step-by-step guide on how to add your code to a GitHub repository. Steps to Add Code on GitHub RepositoryStep 1
2 min read
How To Set Up Merge Queues in GitHub Actions
Managing pull requests (PRs) efficiently in a collaborative development environment is crucial to ensure that the codebase remains stable and conflict-free. With GitHub Actions, automating the PR merging process with merge queues can help streamline your workflow, reduce manual intervention, and ens
6 min read
What are the Project Quality Requirements?
In project management, it is crucial to outline the requirements for the quality of projects. Quality requirements specify the standards and conditions that need to be complied with to ensure a project is completed. They meet stakeholder needs, determine the direction of a project team, and aid in e
9 min read
Requirements Gathering - Introduction, Processes, Benefits and Tools
In the world of software development, the success of a project relies heavily on a crucial yet often overlooked phase: Requirement Gathering. This initial stage acts as the foundation for the entire development life cycle, steering the course of the software and ultimately determining its success. L
15 min read