问题:配置,以便可以从github进行pip安装

我们想在github上使用pip将私有软件包安装到我们的生产服务器上。这个问题关系到github存储库中需要什么才能使安装成功。

假设使用以下命令行(可以正常身份验证并尝试安装):

pip install git+ssh://git@github.com/BlahCo/search/tree/prod_release_branch/ProductName

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

我在这里问是因为我尝试了几种变体,但无法使其正常工作。任何帮助表示赞赏。

We’d like to use pip with github to install private packages to our production servers. This question concerns what needs to be in the github repo in order for the install to be successful.

Assuming the following command line (which authenticates just fine and tries to install):

pip install git+ssh://git@github.com/BlahCo/search/tree/prod_release_branch/ProductName

What needs to reside in the ProductName? Is it the contents of what would normally be in the tar file after running setup.py with the sdist option, or is the actual tar.gz file, or something else?

I’m asking here because I’ve tried several variations and can’t make it work. Any help appreciated.


回答 0

您需要整个python软件包,其中包含一个setup.py文件。

名为的软件包为foo

foo # the installable package
├── foo
   ├── __init__.py
   └── bar.py
└── setup.py

然后像这样从github安装:

$ pip install git+https://github.com/myuser/foo.git@v123
or
$ pip install git+https://github.com/myuser/foo.git@newbranch

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

You need the whole python package, with a setup.py file in it.

A package named foo would be:

foo # the installable package
├── foo
│   ├── __init__.py
│   └── bar.py
└── setup.py

And install from github like:

$ pip install git+ssh://git@github.com/myuser/foo.git
or
$ pip install git+https://github.com/myuser/foo.git@v123
or
$ pip install git+https://github.com/myuser/foo.git@newbranch

More info at https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support


回答 1

我不得不从github repo安装时遇到了类似的问题,但又不想安装git等。

最简单的方法是使用软件包的zip存档。添加/zipball/master到仓库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...

这样,您将使ip可以与github源存储库一起使用。

I had similar issue when I had to install from github repo, but did not want to install git , etc.

The simple way to do it is using zip archive of the package. Add /zipball/master to the 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...

This way you will make pip work with github source repositories.


回答 2

如果您要使用requirements.txt文件,则需要使用git类似下面的条目的名称匿名获取您的中的master分支requirements.txt

对于常规安装:

git+git://github.com/celery/django-celery.git

对于“ 可编辑 ”安装:

-e git://github.com/celery/django-celery.git#egg=django-celery

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

If you want to use requirements.txt file, you will need git and something like the entry below to anonymously fetch the master branch in your requirements.txt.

For regular install:

git+git://github.com/celery/django-celery.git

For “editable” install:

-e git://github.com/celery/django-celery.git#egg=django-celery

Editable mode downloads the project’s source code into ./src in the current directory. It allows pip freeze to output the correct github location of the package.


回答 3

克隆目标存储库的方式与克隆任何其他项目相同:

git clone git@github.com:myuser/foo.git

然后以开发模式安装它:

cd foo
pip install -e .

您可以更改不需要的任何内容,使用foo包的每个代码都将使用修改后的代码。

该解决方案有两个好处:

  1. 您可以在主项目目录中安装软件包。
  2. 软件包包括.git目录,因此它是常规的Git存储库。您可以立即将叉子推入。

Clone target repository same way like you cloning any other project:

git clone git@github.com:myuser/foo.git

Then install it in develop mode:

cd foo
pip install -e .

You can change anything you wan’t and every code using foo package will use modified code.

There 2 benefits ot this solution:

  1. You can install package in your home projects directory.
  2. Package includes .git dir, so it’s regular Git repository. You can push to your fork right away.

回答 4

您可以在Colab中尝试这种方式

!git clone https://github.com/UKPLab/sentence-transformers.git
!pip install -e /content/sentence-transformers
import sentence_transformers

you can try this way in Colab

!git clone https://github.com/UKPLab/sentence-transformers.git
!pip install -e /content/sentence-transformers
import sentence_transformers

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。