从 PyPI 而非 .whl 进行 pip 安装时,对包的 Numpy 安装要求失败

Numpy install requirement on package fails on pip install from PyPI but not from .whl

我最近构建了我的第一个 python 包并尝试使用 test.pypi.org (Github repo Test PyPI)

测试分发

构建 dist 的代码:

python setup.py sdist bdist_wheel

上传到测试 PyPI 的代码:

twine upload --repository testpypi dist/*

然后我创建并清空了 conda env 来测试安装:

conda create --prefix ./envs --no-default-packages python=3.6

在这个环境中,我使用成功 pip install with wheel file:

pip install mathsom-0.1.1-py3-none-any.whl

但是如果我尝试从 Test PyPI 安装它,numpy 安装会失败(它在 install_requirements en setup.cfg 文件中)。代码:

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

Setup.cfg代码:

[metadata]
name = mathsom
author = Oliver Mohr B.
author_email = oliver.mohr.b@gmail.com
version = 0.1.1
description = Personal library for math related problems
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/oliverm91/mathsom
license_files = LICENSE
keywords = solvers, solver, interpolations, interpolation, numerics, derivatives, integrals

[options]
package_dir=
    = src
packages=find:
setup_requires = 
    numpy
install_requires =
    numpy
    scipy

[options.packages.find]
where=src

Setup.py

from setuptools import setup
if __name__ == '__main__':
    setup()

第一行错误(超长错误消息):

如果您查看错误消息,您可以看到

Downloading ... mathsom-0.1.1-py3-none-any.whl

所以它也是使用whl文件。但是,numpy 的安装方式不同。在您的错误消息中,很明显 numpy 正在尝试从源代码编译,这并不奇怪,因为您将索引设置为 https://test.pypi.org/simple/ 并且存在 only source distributions of numpy under that index。如果您允许可以从 pypi 中提取依赖项,通过将 test.pypi 设置为 extra-index 和 --extra-index-url 然后一切正常(在使用您提供的命令创建的新 conda env 中测试) :

pip install --extra-index-url https://test.pypi.org/simple/ mathsom
Looking in indexes: https://pypi.org/simple, https://test.pypi.org/simple/
Collecting mathsom
  Downloading https://test-files.pythonhosted.org/packages/4b/b3/76e6bbaa6c1da9f6f032e114af7f5724077154a28b5fc7069330185f2bc8/mathsom-0.1.1-py3-none-any.whl (18 kB)
Collecting scipy
  Downloading scipy-1.5.4-cp36-cp36m-win_amd64.whl (31.2 MB)
     |████████████████████████████████| 31.2 MB 393 kB/s
Collecting numpy
  Downloading numpy-1.19.5-cp36-cp36m-win_amd64.whl (13.2 MB)
     |████████████████████████████████| 13.2 MB ...
Installing collected packages: numpy, scipy, mathsom
Successfully installed mathsom-0.1.1 numpy-1.19.5 scipy-1.5.4