配置以便 pip install 可以从 github 运行

发布于 2024-12-18 02:55:11 字数 478 浏览 0 评论 0原文

我们想使用 pip 和 github 将私有包安装到我们的生产服务器。这个问题涉及 github 存储库中需要包含哪些内容才能成功安装。

假设以下命令行(可以很好地进行身份验证并尝试安装):

pip install git+ssh://[email protected]/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://[email protected]/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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

尝蛊 2024-12-25 02:55:11

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

名为 foo 的包将是:

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

并从 github 安装,例如:

$ pip install git+ssh://[email protected]/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

更多信息位于 https://pip.pypa.io/en/stable/cli/pip_install/

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://[email protected]/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/cli/pip_install/

心凉怎暖 2024-12-25 02:55:11

当我必须从 github 存储库安装但又不想安装 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...

这样您就可以使 pip 与 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.

别再吹冷风 2024-12-25 02:55:11

如果您想使用 requirements.txt 文件,则需要 git 和类似以下条目的内容来匿名获取 requirements.txt 中的 master 分支代码>.

对于常规安装:

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.

老街孤人 2024-12-25 02:55:11

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

git clone [email protected]:myuser/foo.git

然后以开发模式安装它:

cd foo
pip install -e .

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

此解决方案有 2 个好处:

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

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

git clone [email protected]: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.
甜扑 2024-12-25 02:55:11

这是简单的解决方案

使用 git

pip install git+https://github.com/jkbr/httpie.git

不使用 git

pip install https://github.com/jkbr/httpie/tarball/master

pip install https://github.com/jkbr/httpie/zipball/master  

pip install https://github.com/jkbr/httpie/archive/master.zip

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

Here is the simple solution

With git

pip install git+https://github.com/jkbr/httpie.git

Without git

pip install https://github.com/jkbr/httpie/tarball/master

or

pip install https://github.com/jkbr/httpie/zipball/master  

or

pip install https://github.com/jkbr/httpie/archive/master.zip

Note: You need a python package with the setup.py file in it.

深巷少女 2024-12-25 02:55:11

以下格式可用于通过 GitHub 中的 pip 安装 python 库。

pip install <LibName>@git+ssh://[email protected]/<username>/<LibName>#egg<LibName>

Below format could be use to install python libraries via pip from GitHub.

pip install <LibName>@git+ssh://[email protected]/<username>/<LibName>#egg<LibName>
左岸枫 2024-12-25 02:55:11

你可以在 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
泪意 2024-12-25 02:55:11

使用终端命令测试优化 Ubuntu 解决方案:

第 1 步:
在选定的目录中克隆 git 存储库。

示例:

$ git clone https://github.com/httpie/httpie.git

第 2 步:
选择/更改目录路径、克隆文件夹

$ cd ClonedFolderName

第 3 步:
输入以下命令来安装该软件包

ColnedFolderName(directory Name) $ pip install ./

pip install ./是在克隆目录名称中输入的命令

注意:确保setup.py位于克隆存储库内。 (默认情况下)

Tested Optimized Ubuntu Solution using the terminal command:

Step 1:
In a selected directory clone the git repo.

Example:

$ git clone https://github.com/httpie/httpie.git

Step 2:
select/change path to the directory, to the cloned folder

$ cd ClonedFolderName

Step 3:
Enter following command to install that package

ColnedFolderName(directory Name) $ pip install ./

pip install ./ is command to enter in cloned directory name

Note: Make sure setup.py is inside cloned repo. (which is by default in it)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文