如何使用 pip 从 git 子目录安装? [英] How can I install from a git subdirectory with pip?
问题描述
我有一个包含许多文件夹的 git 存储库,其中一个是可使用 pip 安装的 python 模块,如下所示:
repo.git/回购.git/folder1/仓库.git/folder2/repo.git/mymodule/repo.git/mymodule/__init__.pyrepo.git/mymodule/setup.pyrepo.git/mymodule/...
现在我必须执行以下操作才能安装:
git clone http://server/repo.git光盘回购pip 安装我的模块光盘..rm -rf 回购
是否可以直接用pip安装模块而无需显式克隆?
我试过了:
pip install git+https://server/repo.git/mymodule/pip 安装 git+https://server/repo.git:mymodule/
但我明白了:
IOError: [Errno 2] 没有那个文件或目录:'/tmp/pip-88tlLm-build/setup.py'
有一个拉取请求 关于这个功能,好像一个月前已经合并到develop分支了.语法是以下:
pip install -e git+https://git.repo/some_repo.git#egg=version_subpkg&subdirectory=repo #从repo子目录安装python包
我们可能需要等待一段时间,直到它合并到 master 并分发.
更新:现在可以使用并记录在 https://pip.pypa.io/en/stable/cli/pip_install/#vcs-support 如下:
<块引用>对于 setup.py 不在项目根目录下的项目,子目录"组件被使用.子目录"的值零件应该是从项目根目录到 setup.py 的路径位于.
因此,如果您的存储库布局是:
- pkg_dir/- setup.py # setup.py 用于包``pkg``- some_module.py- 其他目录/- some_file- some_other_file
你需要使用
pip install -e vcs+protocol://repo_url/#egg=pkg&subdirectory=pkg_dir
注意:在 Windows 上,您必须将 URL 放在双引号中,否则您将收到错误'子目录'未被识别为内部或外部命令".例如,使用:
<块引用>pip install -e "vcs+protocol://repo_url#egg=pkg&subdirectory=pkg_dir";
I have a git repository with many folders, one of them being a python module installable with pip, like this:
repo.git/
repo.git/folder1/
repo.git/folder2/
repo.git/mymodule/
repo.git/mymodule/__init__.py
repo.git/mymodule/setup.py
repo.git/mymodule/...
Right now I have to do the following to install:
git clone http://server/repo.git
cd repo
pip install mymodule
cd ..
rm -rf repo
Is it possible to install the module directly with pip without explicitly cloning ?
I tried:
pip install git+https://server/repo.git/mymodule/
pip install git+https://server/repo.git:mymodule/
But I get:
IOError: [Errno 2] No such file or directory: '/tmp/pip-88tlLm-build/setup.py'
There is a pull request regarding this feature, and it seems to have been merged to develop branch a month ago. The syntax is the following:
pip install -e git+https://git.repo/some_repo.git#egg=version_subpkg&subdirectory=repo # install a python package from a repo subdirectory
We probably have to wait for a while until it gets merged to master and is distributed.
UPDATE: This is now available and documented at https://pip.pypa.io/en/stable/cli/pip_install/#vcs-support as follows:
For projects where setup.py is not in the root of project, "subdirectory" component is used. Value of "subdirectory" component should be a path starting from root of the project to where setup.py is located.
So if your repository layout is:
- pkg_dir/ - setup.py # setup.py for package ``pkg`` - some_module.py - other_dir/ - some_file - some_other_file
You'll need to use
pip install -e vcs+protocol://repo_url/#egg=pkg&subdirectory=pkg_dir
Note: On Windows, you must place the URL in double quotes, or you'll get an error "'subdirectory' is not recognized as an internal or external command". E.g., use:
pip install -e "vcs+protocol://repo_url#egg=pkg&subdirectory=pkg_dir"
这篇关于如何使用 pip 从 git 子目录安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!