【问题标题】:Can't install my own PyPi package: requirements can't be satisfied无法安装我自己的 PyPi 包:无法满足要求
【发布时间】:2021-12-01 11:28:36
【问题描述】:

我正在尝试发布一个 PyPI 包。我首先上传到TestPyPI 进行测试。我的setup.py 很简单:

import pathlib
from setuptools import setup, find_packages

# The directory containing this file
HERE = pathlib.Path(__file__).parent

# The text of the README file
README = (HERE / "README.md").read_text()

# This call to setup() does all the work
setup(
    name="my_package_name",
    version="0.0.1",
    description="My first Python package",
    long_description=README,
    long_description_content_type="text/markdown",
    url="https://github.com/my_package_url",
    author="John Smith",
    author_email="john.smith@gmail.com",
    license="MIT",
    classifiers=[
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.7",
    ],
    packages=find_packages(exclude=("test",)),
    include_package_data=True,
    install_requires=[
        "numpy",
        "scipy",
        "pandas",
        "statsmodels",
    ],
)

我关注this tutorial。基本上,一旦 setup.py 准备好,我就会运行

python3 setup.py sdist bdist_wheel

然后

twine upload --repository-url https://test.pypi.org/legacy/ dist/*

最后,为了实际测试我的包安装,我创建了一个新的虚拟环境并运行

pip install -i https://test.pypi.org/simple/ my_package_name

但是,我不断收到与未满足 pandasstatsmodels 要求相关的错误:

ERROR: Could not find a version that satisfies the requirement pandas (from my_package_name) (from versions: none)
ERROR: No matching distribution found for pandas (from my_package_name)

是不是因为 TestPyPI 没有那些包(不像 PyPI)?那么人们通常如何端到端测试他们的包是否可以被其他用户顺利安装?

【问题讨论】:

  • 尝试添加 --no-dependencies 标志以跳过依赖项?

标签: python pip setuptools pypi


【解决方案1】:

您只能拥有一个索引,但您可以拥有任意数量的extra indices。将主 PyPI 添加为额外索引:

pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ my_package_name

首先pip查看索引,然后扫描额外的索引,直到找到包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 2015-07-14
    • 2019-11-28
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多