简体   繁体   English

如何在 setup.py 中使用自定义 PyPI 编写 Python 包?

[英]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.

相关问题 python setup.py install-已经安装了一个软件包,为什么要搜索pypi来安装它? - python setup.py install - already installed a package, why is it searching pypi to install it? 在pypi python setup.py中指定可选的依赖项 - Specifying optional dependencies in pypi python setup.py 使用额外的 python package 索引 url 与 setup.py - Using an extra python package index url with setup.py 如何在自定义 setup.py 步骤中获取目标 Python package 目录? - How to get the target Python package directory in a custom setup.py step? 如何在没有setup.py的情况下将软件包上传到PyPI服务器? - How to upload packages to PyPI server without setup.py? 如何在 Python setup.py 中递归添加 package 数据? - How to add package data recursively in Python setup.py? 如何使用 setup.py 安装托管在私有 PyPI 中的包? - How can I install packages hosted in a private PyPI using setup.py? 如何将个人SCM存储库(不是pypi)中的项目包含到setup.py中? - How to include projects in personal SCM repositories (not in pypi) to setup.py? 如何卸载使用“python setup.py develop”安装的 Python 站点包? - How to uninstall Python site-package which was installed using "python setup.py develop"? 如何更改`setup.py test`以使用不同的Pypi服务器? - How change `setup.py test` to use different Pypi server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM