Home  >  Article  >  Backend Development  >  How to Install Packages Directly from GitHub in requirements.txt?

How to Install Packages Directly from GitHub in requirements.txt?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-12 13:20:02606browse

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:

  • @41b95ec: Commit hash
  • @main: Branch name
  • @0.1: Tag
  • @releases/tag/v3.7.1: Release

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn