gpt4 book ai didi

python - 如何使用 pip 从 git 子目录安装?

转载 作者:IT老高 更新时间:2023-10-28 21:43:41 29 4
gpt4 key购买 nike

我有一个包含许多文件夹的 git 存储库,其中一个是可通过 pip 安装的 python 模块,如下所示:

repo.git/
repo.git/folder1/
repo.git/folder2/
repo.git/mymodule/
repo.git/mymodule/__init__.py
repo.git/mymodule/setup.py
repo.git/mymodule/...

现在我必须执行以下操作才能安装:

git clone http://server/repo.git
cd repo
pip install mymodule
cd ..
rm -rf repo

是否可以直接用 pip 安装模块而无需显式克隆?

我试过了:

pip install git+https://server/repo.git/mymodule/
pip install git+https://server/repo.git:mymodule/

但我明白了:

IOError: [Errno 2] No such file or directory: '/tmp/pip-88tlLm-build/setup.py'

最佳答案

有一个pull request关于这个功能,它似乎在一个月前已经 merge 到开发分支。语法是 following :

pip install -e git+https://git.repo/some_repo.git#egg=version_subpkg&subdirectory=repo # install a python package from a repo subdirectory

我们可能需要等待一段时间,直到它被 merge 到 master 并被分发。

更新:现在可以在 https://pip.pypa.io/en/stable/cli/pip_install/#vcs-support 获得并记录。如下:

For projects where setup.py is not in the root of project,"subdirectory" component is used. Value of "subdirectory" componentshould be a path starting from root of the project to where setup.pyis 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

注意:在 Windows 上,您必须将 URL 放在双引号中,否则您将收到错误消息“'subdirectory' 未被识别为内部或外部命令”。例如,使用:

pip install -e "vcs+protocol://repo_url#egg=pkg&subdirectory=pkg_dir"

关于python - 如何使用 pip 从 git 子目录安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13566200/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com