首页 > 解决方案 > 从 test.pypi 安装自己的包时如何修复“找不到 {package name} 的匹配分发”

问题描述

当我将我的 python 包推送到 test.pypi.org 时,我无法在不同的机器和不同的虚拟环境上安装包。我收到错误消息说我的包的依赖项没有分发,并且错误消息说没有找到满足要求的版本。

我尝试在 setup.py 文件中解析我的 requirements.txt,然后运行python setup.py sdist bdist_wheeltwine upload --repository-url https://test.pypi.org/legacy/ dist/*构建并将其上传到 test.pipy.org,但问题仍然存在。

我的 setup.py 看起来像这样

...


dependencies=''
with open("requirements.txt","r") as f:
        dependencies = f.read().splitlines()


setup(
    name="FlagWaver",
    version="0.0.54",
    description=DESCRIPTION,
    long_description = LONG_DESCRIPTION,
    long_description_content_type = "text/markdown",
    url="https://github.com/ShahriyarShawon/flag-wave",
    author="Shahriyar Shawon",
    author_email="ShahriyarShawon321@gmail.com",
    license="Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International",
    packages = [
        "FlagWaver"
    ],
    classifiers = [
        "Programming Language :: Python :: 3"
    ],
    install_requires = dependencies

)

我运行这个 bash 脚本来构建和上传

#!/bin/zsh

pipenv shell
python setup.py sdist bdist_wheel
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

我的 requirements.txt 看起来像这样

bleach==3.1.0
certifi==2019.6.16
chardet==3.0.4
cycler==0.10.0
docutils==0.15.2
idna==2.8
imageio==2.5.0
kiwisolver==1.1.0
matplotlib==3.1.1
numpy==1.17.0
opencv-python==4.1.0.25
pandas==0.25.0
Pillow==6.1.0
pkginfo==1.5.0.1
Pygments==2.4.2
pyparsing==2.4.2
python-dateutil==2.8.0
pytz==2019.2
readme-renderer==24.0
requests==2.22.0
requests-toolbelt==0.9.1
six==1.12.0
tqdm==4.32.2
twine==1.13.0
urllib3==1.25.3
webencodings==0.5.1

并且每次我尝试运行pip install -i https://test.pypi.org/simple/ FlagWaver(这就是 test.pypi 告诉我安装我的包的方式)它似乎总是选择一个不同的依赖项来抱怨

我期望成功安装我的包以及 requirements.txt 中列出的所有依赖项,同时还能够成功创建 pipfile.lock 文件。相反,我收到错误消息,例如

ERROR: Could not find a version that satisfies the requirement opencv-python==4.1.0.25 (from FlagWaver) (from versions: none)
ERROR: No matching distribution found for opencv-python==4.1.0.25 (from FlagWaver)

注意: opencv-python 可以替换为 requiremnets.txt 文件中列出的任何其他依赖项

标签: pythonpython-3.xpip

解决方案


我没有使用 test.pypi.org,但是当你从那里安装一个包时,它只查找对 test.pypi.org 的依赖项,它没有所有相同的包或与 pypi.org 相同的版本。

根据这篇文章,您可以从 test.pypi.org 中提取您的包,但来自 pypi.org 的依赖项应该可以解决您的问题

“如果你想允许 pip 也从 PyPI 中提取其他包,你可以指定 --extra-index-url 指向 PyPI。当你正在测试的包有依赖项时,这很有用:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple your-package"


推荐阅读