I've installed a library using the command
pip install git+git://github.com/mozilla/elasticutils.git
which installs it directly from a Github repository. This works fine and I want to have that dependency in my requirements.txt
. I've looked at other tickets like this but that didn't solve my problem. If I put something like
-f git+git://github.com/mozilla/elasticutils.git
elasticutils==0.7.dev
in the requirements.txt
file, a pip install -r requirements.txt
results in the following output:
Downloading/unpacking elasticutils==0.7.dev (from -r requirements.txt (line 20))
Could not find a version that satisfies the requirement elasticutils==0.7.dev (from -r requirements.txt (line 20)) (from versions: )
No distributions matching the version for elasticutils==0.7.dev (from -r requirements.txt (line 20))
The documentation of the requirements file does not mention links using the git+git
protocol specifier, so maybe this is just not supported.
Does anybody have a solution for my problem?
First, install with
git+git
orgit+https
, in any way you know. Example of installingkronok
's branch of thebrabeion
project:Second, use
pip freeze > requirements.txt
to get the right thing in yourrequirements.txt
. In this case, you will getThird, test the result:
“Editable” packages syntax can be used in
requirements.txt
to import packages from a variety of VCS (git, hg, bzr, svn):Also, it is possible to point to particular commit:
Since pip
v1.5
, (released Jan 1 2014: CHANGELOG, PR) you may also specify a subdirectory of a git repo to contain your module. The syntax looks like this:Note: As a pip module author, ideally you'd probably want to publish your module in it's own top-level repo if you can. Yet this feature is helpful for some pre-existing repos that contain python modules in subdirectories. You might be forced to install them this way if they are not published to pypi too.
requirements.txt
allows the following ways of specifying a dependency on a package in a git repository as of pip 7.0:1For Github that means you can do (notice the omitted
-e
):Why the extra answer?
I got somewhat confused by the
-e
flag in the other answers so here's my clarification:The
-e
or--editable
flag means that the package is installed in<venv path>/src/SomeProject
and thus not in the deeply buried<venv path>/lib/pythonX.X/site-packages/SomeProject
it would otherwise be placed in.2Documentation
Normally your
requirements.txt
file would look something like this:To specify a Github repo, you do not need the
package-name==
convention.The examples below update
package-two
using a GitHub repo. The text between@
and#
denotes the specifics of the package.Specify commit hash (
41b95ec
in the context of updatedrequirements.txt
):Specify branch name (
master
):Specify tag (
0.1
):Specify release (
3.7.1
):Note that
#egg=package-two
is not a comment here, it is to explicitly state the package nameThis blog post has some more discussion on the topic.