使用 setuptools 从 VCS repo 子目录安装依赖项
Installing dependency from a VCS repo subdirectory using setuptools
我正在尝试使用 setuptools 从 VCS 和子目录中安装依赖项。
我的 setup.py
看起来像这样:
#!/usr/bin/env python3
from setuptools import setup
required = [
"package"
]
dependency_links = [
"git+ssh://git@host/repo.git@tag#subdirectory=subdir#egg=package-version"
]
setup(install_requires=required, dependency_links=dependency_links)
运行 python3 setup.py install
在 virtualenv 中,我得到以下错误:
Download error on git+ssh://git@host/repo.git@tag#subdirectory=subdir#egg=package-version: unknown url type: git+ssh -- Some packages may not be found!
为了调试,我使用了以下 public Github 存储库:
required = [
"pycocotools"
]
dependency_links = [
"git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI#egg=pycocotools-2.0"
]
这个例子被建议 here 作为类似问题的解决方案。
我得到了同样的 unknown url type
错误(包最终是通过 PyPI 检索的,而不是通过 VCS URL !)。
我试过的
git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI#egg=pycocotools-2.0
python3 setup.py install
: unknown url type: git+https -- Some packages may not be found!
pip3 install
: ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/tmp/pip-install-lwpbj7yv/pycocotools-2.0/PythonAPI#egg=pycocotools-2.0': '/tmp/pip-install-lwpbj7yv/pycocotools-2.0/PythonAPI#egg=pycocotools-2.0'
git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools-2.0
python3 setup.py install
: unknown url type: git+https -- Some packages may not be found!
pip3 install
:好的,但是 WARNING: Generating metadata for package pycocotools-2.0 produced metadata for project name pycocotools. Fix your #egg=pycocotools-2.0 fragments.
git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools
python3 setup.py install
: unknown url type: git+https -- Some packages may not be found!
pip3 install
: 好的
我也尝试删除所有这些 URL 的 git+
,但 cannot detect archive format
.
我使用的版本
- 安装工具 46.4.0
- python 3.6.9
- 点 20.1.1
dependency_links
被宣布为过时,最终 removed 在 pip
19.0 中。它的替代品是具有特殊语法的 install_requires
(自 pip
19.1 起支持):
install_requires=[
'package_name @ git+https://gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>'
]
见https://pip.readthedocs.io/en/stable/reference/pip_install/#requirement-specifiers and https://www.python.org/dev/peps/pep-0440/#direct-references
这需要 pip install
,包括 pip install .
,不适用于 python setup.py install
。
你的情况:
install_requires=[
"package @ git+ssh://git@host/repo.git@tag#subdirectory=subdir"
]
setup(install_requires=install_requires)
例如:
install_requires=[
pycocotools @ git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI
]
我正在尝试使用 setuptools 从 VCS 和子目录中安装依赖项。
我的 setup.py
看起来像这样:
#!/usr/bin/env python3
from setuptools import setup
required = [
"package"
]
dependency_links = [
"git+ssh://git@host/repo.git@tag#subdirectory=subdir#egg=package-version"
]
setup(install_requires=required, dependency_links=dependency_links)
运行 python3 setup.py install
在 virtualenv 中,我得到以下错误:
Download error on git+ssh://git@host/repo.git@tag#subdirectory=subdir#egg=package-version: unknown url type: git+ssh -- Some packages may not be found!
为了调试,我使用了以下 public Github 存储库:
required = [
"pycocotools"
]
dependency_links = [
"git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI#egg=pycocotools-2.0"
]
这个例子被建议 here 作为类似问题的解决方案。
我得到了同样的 unknown url type
错误(包最终是通过 PyPI 检索的,而不是通过 VCS URL !)。
我试过的
git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI#egg=pycocotools-2.0
python3 setup.py install
:unknown url type: git+https -- Some packages may not be found!
pip3 install
:ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/tmp/pip-install-lwpbj7yv/pycocotools-2.0/PythonAPI#egg=pycocotools-2.0': '/tmp/pip-install-lwpbj7yv/pycocotools-2.0/PythonAPI#egg=pycocotools-2.0'
git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools-2.0
python3 setup.py install
:unknown url type: git+https -- Some packages may not be found!
pip3 install
:好的,但是WARNING: Generating metadata for package pycocotools-2.0 produced metadata for project name pycocotools. Fix your #egg=pycocotools-2.0 fragments.
git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools
python3 setup.py install
:unknown url type: git+https -- Some packages may not be found!
pip3 install
: 好的
我也尝试删除所有这些 URL 的 git+
,但 cannot detect archive format
.
我使用的版本
- 安装工具 46.4.0
- python 3.6.9
- 点 20.1.1
dependency_links
被宣布为过时,最终 removed 在 pip
19.0 中。它的替代品是具有特殊语法的 install_requires
(自 pip
19.1 起支持):
install_requires=[
'package_name @ git+https://gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>'
]
见https://pip.readthedocs.io/en/stable/reference/pip_install/#requirement-specifiers and https://www.python.org/dev/peps/pep-0440/#direct-references
这需要 pip install
,包括 pip install .
,不适用于 python setup.py install
。
你的情况:
install_requires=[
"package @ git+ssh://git@host/repo.git@tag#subdirectory=subdir"
]
setup(install_requires=install_requires)
例如:
install_requires=[
pycocotools @ git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI
]