【问题标题】:How to fix 'Could not find a version that satisfies the requirement' for install_requires list when pip installing in custom package?在自定义软件包中安装 pip 时,如何解决 install_requires 列表的“找不到满足要求的版本”?
【发布时间】:2021-01-09 20:15:34
【问题描述】:

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

所以我先运行:

python3 setup.py sdist bdist_wheel

其中我的 setup.py install_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 需求列表?

【问题讨论】:

  • 按照这个步骤https://medium.com/@joel.barmettler/how-to-upload-your-python-package-to-pypi-65edc5fe9c56

标签: python-3.x pip setup.py pypi twine


【解决方案1】:

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

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

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

您可以通过指定 --extra-index-url 代替,将 pip 配置为在缺少包时回退到 TestPyPI:

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

【讨论】:

  • 谢谢。我被 --index-url 震惊了,而我应该使用 --extra-index-url。
猜你喜欢
  • 2021-12-25
  • 2018-10-04
  • 2016-12-18
  • 2021-02-21
  • 2023-03-12
  • 2018-09-19
  • 1970-01-01
相关资源
最近更新 更多