[英]How to author Python package using custom PyPI in setup.py?
Let's say I have no internet, and a custom PyPI clone running at 10.0.0.2.假设我没有互联网,并且有一个在 10.0.0.2 上运行的自定义 PyPI 克隆。
I want to be author a Python package that someone on my intranet can install.我想成为一个 Python 包的作者,我的 Intranet 上的某个人可以安装它。 It has dependency X, which lives on my custom PyPI clone.它有依赖项 X,它存在于我的自定义 PyPI 克隆上。
How can I author my package so that someone can install it, pulling in dependency X, without needing to apply any special pip configuration?我如何创作我的包,以便有人可以安装它,引入依赖项 X,而无需应用任何特殊的 pip 配置? That is, how can I author my package so that installing it pulls in custom PyPI dependencies?也就是说,我如何编写我的包以便安装它时会引入自定义 PyPI 依赖项? In this constraint, I only have access to edit the setup.py
.在此约束中,我只能编辑setup.py
。
The context is that I am using a managed service that accepts a tar'd Python package with a setup.py file, and then runs pip to install everything.上下文是我使用的托管服务接受带有 setup.py 文件的 tar'd Python 包,然后运行 pip 来安装所有内容。 I don't have access to how pip is called, or any environmental config on that system.我无权访问 pip 的调用方式,也无权访问该系统上的任何环境配置。
Is there a way through setup.py alone to pull in packages from a custom IP address for a PyPI?有没有办法单独通过 setup.py 从 PyPI 的自定义 IP 地址中提取包?
As far as I'm aware, you can't update the setup.py to point it to download dependencies from a specific server.据我所知,您无法更新 setup.py 以将其指向从特定服务器下载依赖项。 However, the person that's executing the pip install can specify which server to use to look for the package and its dependencies with the -i flag like so但是,执行 pip install 的人可以使用 -i 标志指定使用哪个服务器来查找包及其依赖项,如下所示
pip install -i http://localhost:8000 <package>
The dependencies can be specified in the setup.py, on the other hand.另一方面,可以在 setup.py 中指定依赖项。 In setuptools.setup you can declare dependencies like so:在 setuptools.setup 中,您可以像这样声明依赖项:
import sys
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="somepackage",
version="0.0.1",
author="Your Name",
author_email="no.replies@example.com",
description="Some desc",
long_description=long_description,
long_description_content_type="text/markdown",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.8"
],
install_requires=["dependency1", "dependency2"]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.