首页 > 解决方案 > 在自定义软件包中进行 pip 安装时,如何解决 install_requires 列表的“找不到满足要求的版本”?

问题描述

我正在尝试使用 twine 包构建我自己的 Python 包(可通过 pip 安装)。这一切都很顺利,直到我尝试 pip 安装我的实际包(所以在上传到 PyPi 之后)。

所以我首先运行:

python3 setup.py sdist bdist_wheel

我的 setup.pyinstall_requires列表如下所示:

install_requires=[
'jupyter_kernel_gateway==2.4.0',
'pandas==1.0.2',
'numpy==1.18.1',
'azure-storage-blob==2.0.1',
'azure-datalake-store==0.0.48',
'psycopg2-binary==2.8.4',
'xlsxwriter==1.2.6',
'SQLAlchemy==1.3.12',
'geoalchemy2==0.6.3',
'tabulate==0.8.2',
'pyproj==1.9.6',
'geopandas==0.4.0',
'contextily==0.99.0',
'matplotlib==3.0.2',
'humanize==0.5.1',
'ujson==1.35',
'singleton-decorator==1.0.0',
'dataclasses==0.6',
'xlrd==1.2.0'],

据我了解,这些 install_requires 将在安装我自己的软件包时由 pip 安装。

在这之后我跑

python3 -m twine upload --repository testpypi dist/*

将我的包实际上传到 PyPi。但是,当 pip 安装我的包时,我收到错误说没有满足许多列出的要求的版本。例如:ERROR: Could not find a version that satisfies the requirement psycopg2-binary==2.8.4

当我手动安装这些包(例如pip install psycopg2-binary==2.8.4)时,它们会被安装。

有什么方法可以让我的包的 pip install 实际install_requires成功安装需求列表?

标签: python-3.xpipsetup.pypypitwine

解决方案


你没有展示你pip install的包裹,但我猜你正在使用类似的东西:

pip install your_project --index-url https://test.pypi.org/simple

问题是 TestPyPI 不包含 PyPI 上存在的依赖项的副本。例如:

您可以将 pip 配置为在缺少包时回退到 TestPyPI,方法是指定--extra-index-url

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

推荐阅读