0

所以我有一个很常见的问题。但我没有找到我在 SO 上或我自己寻求的答案。

我正在使用 numpy 头文件编译一个带有 c++ 扩展的包。

创建测试环境的过程是从以下conda env 文件创建环境。

name: debug
channels:
  - defaults
dependencies:
  - _libgcc_mutex=0.1=main
  - ca-certificates=2021.10.26=h06a4308_2
  - certifi=2021.10.8=py39h06a4308_0
  - intel-openmp=2021.4.0=h06a4308_3561
  - joblib=1.1.0=pyhd3eb1b0_0
  - ld_impl_linux-64=2.35.1=h7274673_9
  - libffi=3.3=he6710b0_2
  - libgcc-ng=9.3.0=h5101ec6_17
  - libgfortran-ng=7.5.0=ha8ba4b0_17
  - libgfortran4=7.5.0=ha8ba4b0_17
  - libopenblas=0.3.13=h4367d64_0
  - libstdcxx-ng=9.3.0=hd4cf53a_17
  - ncurses=6.3=h7f8727e_2
  - openssl=1.1.1l=h7f8727e_0
  - pip=21.2.4=py39h06a4308_0
  - python=3.9.7=h12debd9_1
  - readline=8.1=h27cfd23_0
  - setuptools=58.0.4=py39h06a4308_0
  - six=1.16.0=pyhd3eb1b0_0
  - sqlite=3.36.0=hc218d9a_0
  - threadpoolctl=2.2.0=pyh0d69192_0
  - tk=8.6.11=h1ccaba5_0
  - tzdata=2021e=hda174b7_0
  - wheel=0.37.0=pyhd3eb1b0_1
  - xz=5.2.5=h7b6447c_0
  - zlib=1.2.11=h7b6447c_3

在这之后我安装numpy

pip install numpy==1.21.3

(我也尝试从 conda 安装它。)

在此之后我安装我的项目

pip install . or python -m pip install .

在我的测试环境中,当我运行测试时,出现以下错误。

RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe

所以首先,错误很明显,所以如果我升级到 numpy 1.22.0,它就可以工作了。

但我想了解的是为什么它说它是针对 0xf 编译的。我也尝试在没有构建隔离的情况下构建,它是一样的。我检查了我的PATHPYTHONPATH,似乎没有冲突路径。当我在setup.py中导入 numpy 时,它说 numpy 的版本是 1.21.3

这是我的pyproject.toml文件的头部。

[build-system]
requires = [
    "setuptools",
    "wheel",
    "numpy==1.21.3"
]
build-backend = "setuptools.build_meta"

这是我的 setup.py 中有趣的部分:

setup(name='xxx',
      version='xxx',
      author="xxx",
      author_email="xxx",
      license='xxx',
      url="xxx",
      description='xxx',
      install_requires=['scipy', 'numpy>=1.21.3', 'scikit-learn'],
      ext_modules=[xxx],
      packages=find_packages(),
      cmdclass={'sdist': sdistzip},
      py_modules=['xxx'])

你有提示我为什么会出现这样的错误吗?为什么它是针对 0xf 编译的?

4

1 回答 1

0

我不知道确切原因,但更改 py_modules 名称解决了我的问题。

于 2022-01-14T14:12:20.090 回答