配置,以便pip安装可以从github工作

ccg*_*ett 211 python git pip

我们想使用pip和github将私有包安装到我们的生产服务器上.这个问题涉及到github仓库中需要什么才能使安装成功.

假设以下命令行(验证正常并尝试安装):

pip install git+ssh://git@github.com/BlahCo/search/tree/prod_release_branch/ProductName
Run Code Online (Sandbox Code Playgroud)

什么需要驻留在ProductName中?它是使用sdist选项运行setup.py之后通常在tar文件中的内容,还是实际的tar.gz文件或其他内容?

我在这里问,因为我尝试了几种变化而无法使其发挥作用.任何帮助赞赏.

Hug*_*res 275

你需要整个python包,里面有一个setup.py文件.

名为的包foo将是:

foo # the installable package
??? foo
?   ??? __init__.py
?   ??? bar.py
??? setup.py
Run Code Online (Sandbox Code Playgroud)

并从github安装如下:

$ pip install git+https://github.com/myuser/foo.git@v123
or
$ pip install git+https://github.com/myuser/foo.git@newbranch
Run Code Online (Sandbox Code Playgroud)

更多信息,访问https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support

  • 这是新的url方案:`pip install git + https:// github.com/pypa/pip.git`来源:[pip Github repo](https://github.com/pypa/pip/issues/539#issuecomment -5825986) (11认同)
  • 不,这是不可能的.pip只从root存储库目录安装,至少对于git.不知道颠覆行为如何...... (3认同)
  • 以上作品,非常感谢.但是如果我在repo中的子目录中发布了什么,那么而不是foo.git我正在寻找foo/releases/ProductVer.这是可能的,如果可能的话怎么样?非常感谢您的帮助! (2认同)
  • 如果你想通过ssh和私人回购这样做,[这是关于如何做到这一点的帖子](http://jtushman.github.io/blog/2013/06/17/sharing-code-across-applications-与-蟒/) (2认同)

小智 106

当我不得不从github repo安装时,我有类似的问题,但不想安装git等.

这样做的简单方法是使用包的zip存档.添加/zipball/master到repo URL:

    $ pip install https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
Downloading/unpacking https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
  Downloading master
  Running setup.py egg_info for package from https://github.com/hmarr/django-debug-toolbar-mongo/zipball/master
Installing collected packages: django-debug-toolbar-mongo
  Running setup.py install for django-debug-toolbar-mongo
Successfully installed django-debug-toolbar-mongo
Cleaning up...
Run Code Online (Sandbox Code Playgroud)

这样你就可以使用github源代码库进行pip工作了.

  • 这是唯一可以在Windows下运行的答案 (2认同)

wie*_*990 26

如果你想使用requirements.txt文件,你将需要git和下面的条目类似地匿名获取你的主分支requirements.txt.

对于常规安装:

git+git://github.com/celery/django-celery.git
Run Code Online (Sandbox Code Playgroud)

对于" 可编辑 "安装:

-e git://github.com/celery/django-celery.git#egg=django-celery
Run Code Online (Sandbox Code Playgroud)

可编辑模式将项目的源代码下载到./src当前目录中.它允许pip freeze输出包的正确github位置.

  • 鸡蛋的名字从哪里来?用github repo替换pip包后,它无法在django中加载包 (2认同)

ava*_*chy 11

像克隆任何其他项目一样克隆目标存储库:

git clone git@github.com:myuser/foo.git
Run Code Online (Sandbox Code Playgroud)

然后在开发模式下安装它:

cd foo
pip install -e .
Run Code Online (Sandbox Code Playgroud)

你可以改变你想要的任何东西,使用foo包的每个代码都将使用修改后的代码.

这个解决方案有两个好处:

  1. 您可以在主项目目录中安装软件包.
  2. 包中包含.gitdir,因此它是常规的Git存储库.你可以马上推到你的前叉.

  • 我可以证明这个解决方案是神奇的。就我而言,我想破解 `pip`,所以我克隆了 `pip` 存储库,创建了一个 virtualenv,激活了它,然后执行了 `pip install -e .`。然后virtualenv中的`pip`处于开发模式!令我印象深刻的是,即使使用包管理器本身,这也能正常工作。 (2认同)

Suh*_*ote 6

这是简单的解决方案

用git

pip install git+https://github.com/jkbr/httpie.git
Run Code Online (Sandbox Code Playgroud)

没有git

pip install https://github.com/jkbr/httpie/tarball/master
Run Code Online (Sandbox Code Playgroud)

或者

pip install https://github.com/jkbr/httpie/zipball/master  
Run Code Online (Sandbox Code Playgroud)

或者

pip install https://github.com/jkbr/httpie/archive/master.zip
Run Code Online (Sandbox Code Playgroud)

注意:您需要一个包含 setup.py 文件的 python 包。