pip和tox忽略完整路径依赖,而是在pypi中查找“最佳匹配”

2024-09-28 12:16:21 发布

您现在位置:Python中文网/ 问答频道 /正文

这是SOsetup.py ignores full path dependencies, instead looks for "best match" in pypi的一个扩展

我正在尝试编写setup.py,以便从内部网站上的.tar.gz文件安装专有软件包。不幸的是,对我来说,prop包名称与publicpypi中的一个公共包重复,因此我需要强制在特定版本安装专有包。我正在从Debian Buster基础映像构建docker映像,因此pip、setuptools和tox都是新安装的,该映像将python 3.8和pip升级到21.2.4版

解决方案1-依赖关系链接

我按照上面链接的帖子中的说明将prop包放在install_requiresdependency_links中。以下是my setup.py中的相关行:

    install_requires=["requests", "proppkg==70.1.0"],
    dependency_links=["https://site.mycompany.com/path/to/proppkg-70.1.0.tar.gz#egg=proppkg-70.1.0"]

如果我在包目录中运行python3 setup.py install,则在Debian Buster中安装成功。我看到专有软件包被下载和安装

如果我运行pip3 install .,安装就会失败。同样tox(版本3.24.4)也会失败。在这两种情况下,pip都会显示一条消息“查找索引”,然后失败并显示“错误:找不到满足要求的版本”

解决方案2-PEP 508

研究答案pip ignores dependency_links in setup.py表明依赖关系链接已被弃用,我重新开始,修改setup.py,使其具有:

    install_requires=[
        "requests", 
        "proppkg @ https://site.mycompany.com/path/to/proppkg-70.1.0.tar.gz#egg=proppkg-70.1.0"
    ],

如果我在包目录中运行pip3 install .,则在Debian Buster中安装成功。Pip显示一条消息“查找索引”,但仍然成功下载并安装了专有软件包

如果我在包目录中运行python3 setup.py install,则在Debian Buster中安装失败。我看到这些信息:

Searching for proppkg@ https://site.mycompany.com/path/to/proppkg-70.1.0.tar.gz#egg=proppkg-70.1.0
..
Reading https://pypi.org/simple/proppkg/
..
error: Could not find suitable distribution for Requirement.parse(...). 

Tox在这种情况下也会失败,因为它安装了依赖项

现在真的在猜测,似乎有一个订购问题。Tox调用pip的方式如下:

python -m pip install --exists-action w .tox/.tmp/package/1/te-0.3.5.zip

在该输出中,我将“收集proppkg@https://site.mycompany.com/path/to/proppkg-70.1.0.tar.gz#egg=proppkg-70.1.0"视为第一步。该安装失败,因为它无法导入包请求。然后tox继续收集其他依赖项。最后tox报告为其最后一步“收集请求”(并且成功)。我是否需要担心安装步骤的顺序

我开始认为可能是专有软件包坏了。我验证了prop package setup.py在其install_requires条目中有requests。不确定还要检查什么

解决方案

我的解决方法是在安装自己的软件包之前,在docker映像中单独安装专有软件包,只需运行pip3 install https://site.mycompany.com/path/to/proppkg-70.1.0.tar.gz。setup.py在install_requires中有PEP508 URL。然后pip和tox在pip缓存中找到prop软件包,工作正常

请建议如何尝试最新的pip和tox,或者如果这是最好的,提前感谢

更新-添加setup.py

这是我的软件包setup.py的一个(稍微消毒过的)版本

from setuptools import setup, find_packages


def get_version():
    """
    read version string
    """
    version_globals = {}
    with open("te/version.py") as fp:
        exec(fp.read(), version_globals)
    return version_globals['__version__']


setup(
    name="te",
    version=get_version(),
    packages=find_packages(exclude=["tests.*", "tests"]),
    author="My Name",
    author_email="email@mycompany.com",
    description="My Back-End Server",
    entry_points={"console_scripts": [
                    "te-be=te.server:main"
                  ]},
    python_requires=">=3.7",
    install_requires=["connexion[swagger-ui]",
                      "Flask",
                      "gevent",
                      "redis",
                      "requests",
                      "proppkg @ https://site.mycompany.com/path/to/proppkg-70.1.0.tar.gz#egg=proppkg-70.1.0"
                      ],
    package_data={"te": ["openapi_te.yml"]},
    include_package_data=True,  # read MANIFEST.in
)

Tags: installpippathpyhttpscomtoxversion

热门问题