Python 如何在requirements.txt中声明直接github源代码
我已经使用命令安装了一个库Python 如何在requirements.txt中声明直接github源代码,python,github,pip,requirements.txt,Python,Github,Pip,Requirements.txt,我已经使用命令安装了一个库 pip install git+git://github.com/mozilla/elasticutils.git 它直接从Github存储库安装。这很好,我希望在我的requirements.txt中有这种依赖关系。我看过其他类似的票,但这并没有解决我的问题。如果我把 -f git+git://github.com/mozilla/elasticutils.git elasticutils==0.7.dev 在requirements.txt文件中,一个pip安
pip install git+git://github.com/mozilla/elasticutils.git
它直接从Github存储库安装。这很好,我希望在我的requirements.txt
中有这种依赖关系。我看过其他类似的票,但这并没有解决我的问题。如果我把
-f git+git://github.com/mozilla/elasticutils.git
elasticutils==0.7.dev
在requirements.txt
文件中,一个pip安装-r requirements.txt
会产生以下输出:
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))
没有提到使用git+git
protocol说明符的链接,所以这可能就是不支持的
有人能解决我的问题吗?可以在requirements.txt
中使用,从以下各种位置导入软件包:
此外,还可以指向特定的提交:
-e git://github.com/mozilla/elasticutils.git@000b14389171a9f0d7d713466b32bc649b0bed8e#egg=elasticutils
可在requirements.txt
中使用,以从以下各种文件导入软件包:
此外,还可以指向特定的提交:
-e git://github.com/mozilla/elasticutils.git@000b14389171a9f0d7d713466b32bc649b0bed8e#egg=elasticutils
首先,以您知道的任何方式使用
git+git
或git+https
安装。安装brabeion
项目的kronok
分支的示例:
pip install -e git+https://github.com/kronok/brabeion.git@12efe6aa06b85ae5ff725d3033e38f624e0a616f#egg=brabeion
其次,使用pipfreeze>requirements.txt
在requirements.txt
中获取正确的内容。在这种情况下,您将获得
-e git+https://github.com/kronok/brabeion.git@12efe6aa06b85ae5ff725d3033e38f624e0a616f#egg=brabeion-master
第三,测试结果:
pip uninstall brabeion
pip install -r requirements.txt
首先,以您知道的任何方式使用
git+git
或git+https
安装。安装brabeion
项目的kronok
分支的示例:
pip install -e git+https://github.com/kronok/brabeion.git@12efe6aa06b85ae5ff725d3033e38f624e0a616f#egg=brabeion
其次,使用pipfreeze>requirements.txt
在requirements.txt
中获取正确的内容。在这种情况下,您将获得
-e git+https://github.com/kronok/brabeion.git@12efe6aa06b85ae5ff725d3033e38f624e0a616f#egg=brabeion-master
第三,测试结果:
pip uninstall brabeion
pip install -r requirements.txt
由于pip
v1.5
,(2014年1月1日发布:,),您还可以指定git回购的子目录来包含您的模块。语法如下所示:
pip install -e git+https://git.repo/some_repo.git#egg=my_subdir_pkg&subdirectory=my_subdir_pkg # install a python package from a repo subdirectory
package-one==1.9.4
package-two==3.7.1
package-three==1.0.1
...
注意:作为pip模块的作者,理想情况下,如果可以的话,您可能希望在自己的顶级repo中发布您的模块。然而,这个特性对于一些在子目录中包含python模块的预先存在的repo是有帮助的。如果它们没有发布到pypi,您可能会被迫以这种方式安装它们。由于pip
v1.5版(2014年1月1日发布:),您还可以指定git repo的子目录来包含您的模块。语法如下所示:
pip install -e git+https://git.repo/some_repo.git#egg=my_subdir_pkg&subdirectory=my_subdir_pkg # install a python package from a repo subdirectory
package-one==1.9.4
package-two==3.7.1
package-three==1.0.1
...
注意:作为pip模块的作者,理想情况下,如果可以的话,您可能希望在自己的顶级repo中发布您的模块。然而,这个特性对于一些在子目录中包含python模块的预先存在的repo是有帮助的。如果它们没有发布到pypi,您可能会被迫以这种方式安装它们。requirements.txt
允许以下方法指定从pip 7.0:1开始对git存储库中的包的依赖关系
对于Github,这意味着您可以执行以下操作(注意省略的-e
):
为什么要额外回答?
我对其他答案中的-e
标志有些困惑,因此我的澄清如下:
-e
或-editable
标志意味着包安装在/src/SomeProject
中,因此不在深埋的/lib/pythonX.X/site packages/SomeProject
中。2
文档
- 一,
- 二,
requirements.txt
允许以下方法指定从pip 7.0:1开始对git存储库中的包的依赖关系
对于Github,这意味着您可以执行以下操作(注意省略的-e
):
为什么要额外回答?
我对其他答案中的-e
标志有些困惑,因此我的澄清如下:
-e
或-editable
标志意味着包安装在/src/SomeProject
中,因此不在深埋的/lib/pythonX.X/site packages/SomeProject
中。2
文档
- 一,
- 二,
通常您的requirements.txt
文件如下所示:
pip install -e git+https://git.repo/some_repo.git#egg=my_subdir_pkg&subdirectory=my_subdir_pkg # install a python package from a repo subdirectory
package-one==1.9.4
package-two==3.7.1
package-three==1.0.1
...
要指定Github repo,您不需要包名==
约定
下面的示例使用GitHub repo更新包二。@
和#
之间的文本表示软件包的具体信息
指定提交哈希(41b95ec
在更新的requirements.txt
上下文中):
指定分支名称(master
):
指定标记(0.1
):
指定版本(3.7.1
):
请注意,#egg=package two
在这里不是注释,而是
对该主题进行了更多讨论。通常您的requirements.txt
文件如下所示:
pip install -e git+https://git.repo/some_repo.git#egg=my_subdir_pkg&subdirectory=my_subdir_pkg # install a python package from a repo subdirectory
package-one==1.9.4
package-two==3.7.1
package-three==1.0.1
...
要指定Github repo,您不需要包名==
约定
下面的示例使用GitHub repo更新包二。@
和#
之间的文本表示软件包的具体信息
指定提交哈希(41b95ec
在更新的requirements.txt
上下文中):
指定分支名称(master
):
指定标记(0.1
):
指定版本(3.7.1
):
请注意,#egg=package two
在这里不是注释,而是
我发现让pip3(v9.0.1,由Ubuntu18.04的软件包管理器安装)实际安装我告诉它要安装的东西有点棘手。我发布这个答案是为了节省遇到这个问题的人的时间
将其放入requirements.txt文件失败:
git+git://github.com/myname/myrepo.git@my-branch#egg=eggname
我所说的“失败”是指,当它从Git下载代码时,它最终安装了PyPi上的原始版本的代码,而不是该分支上repo中的代码
但是,安装commmit而不是分支名称是可行的:
git+git://github.com/myname/myrepo.git@d27d07c9e862feb939e56d0df19d5733ea7b4f4d#egg=eggname
我发现它是亲戚
git+https://github.com/path_to_my_project.git