Home > Article > Backend Development > How to Install Packages Directly from GitHub in requirements.txt?
How to Install Packages Directly from GitHub in requirements.txt
In certain situations, developers may need to install dependencies directly from a specific GitHub repository. While the pip install git git://github.com/example/repo.git command effortlessly installs such libraries, encapsulating this dependency in a requirements.txt can prove troublesome.
Problem:
Attempts to include a -f directive in requirements.txt, such as:
-f git+git://github.com/mozilla/elasticutils.git elasticutils==0.7.dev
result in an error during pip install -r requirements.txt:
"Could not find a version that satisfies the requirement elasticutils==0.7.dev"
Solution:
Traditionally, requirements.txt specifies dependencies using the package-name==version convention. However, when referencing GitHub repositories, this format is not required:
package-one==1.9.4 package-two @ git+https://github.com/owner/repo@41b95ec package-three==1.0.1
In the above example, @ denotes a GitHub reference. The following suffixes can be applied to specify various sources:
Note:
In some pip versions, updates to packages installed through the GitHub repository reference may not be detected unless the package's setup.py version is manually incremented.
The above is the detailed content of How to Install Packages Directly from GitHub in requirements.txt?. For more information, please follow other related articles on the PHP Chinese website!