配置以便 pip install 可以从 github 运行
我们想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您需要整个 python 包,其中包含一个 setup.py 文件。
名为
foo
的包将是:并从 github 安装,例如:
更多信息位于 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:And install from github like:
More info at https://pip.pypa.io/en/stable/cli/pip_install/
当我必须从 github 存储库安装但又不想安装 git 等时,我遇到了类似的问题。
简单的方法是使用包的 zip 存档。将
/zipball/master
添加到存储库 URL:这样您就可以使 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:This way you will make pip work with github source repositories.
如果您想使用
requirements.txt
文件,则需要git
和类似以下条目的内容来匿名获取requirements.txt
中的 master 分支代码>.对于常规安装:
对于“可编辑”安装:
可编辑模式将项目的源代码下载到当前目录中的
./src
中。它允许 pip freeze 输出包的正确 github 位置。If you want to use
requirements.txt
file, you will needgit
and something like the entry below to anonymously fetch the master branch in yourrequirements.txt
.For regular install:
For "editable" install:
Editable mode downloads the project's source code into
./src
in the current directory. It allowspip freeze
to output the correct github location of the package.像克隆任何其他项目一样克隆目标存储库:
然后以开发模式安装它:
您可以更改任何您不需要的内容,并且使用
foo
包的每个代码都将使用修改后的代码。此解决方案有 2 个好处:
.git
目录,因此它是常规的 Git 存储库。您可以立即将叉子推到叉子上。Clone target repository same way like you cloning any other project:
Then install it in develop mode:
You can change anything you wan't and every code using
foo
package will use modified code.There 2 benefits ot this solution:
.git
dir, so it's regular Git repository. You can push to your fork right away.这是简单的解决方案
使用 git
不使用 git
或
或
注意:您需要一个包含 setup.py 文件的 python 包。
Here is the simple solution
With git
Without git
or
or
Note: You need a python package with the setup.py file in it.
以下格式可用于通过
GitHub
中的pip
安装python
库。Below format could be use to install
python
libraries viapip
fromGitHub
.你可以在 Colab 中尝试这种方式
you can try this way in Colab
使用终端命令测试优化 Ubuntu 解决方案:
第 1 步:
在选定的目录中克隆 git 存储库。
示例:
第 2 步:
选择/更改目录路径、克隆文件夹
第 3 步:
输入以下命令来安装该软件包
pip install ./是在克隆目录名称中输入的命令
注意:确保setup.py位于克隆存储库内。 (默认情况下)
Tested Optimized Ubuntu Solution using the terminal command:
Step 1:
In a selected directory clone the git repo.
Example:
Step 2:
select/change path to the directory, to the cloned folder
Step 3:
Enter following command to install that package
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)