从test.pypi安装自己的包时如何解决“找不到{包名称}的匹配发行版”

Sha*_*won 10 python pip python-3.x

当我将我的 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

)
Run Code Online (Sandbox Code Playgroud)

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

#!/bin/zsh

pipenv shell
python setup.py sdist bdist_wheel
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Run Code Online (Sandbox Code Playgroud)

我的 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
Run Code Online (Sandbox Code Playgroud)

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

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

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
Run Code Online (Sandbox Code Playgroud)

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

小智 8

我没有使用过 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