Search code examples
pythonnumpybuildsetuptoolspyproject.toml

Numpy version mismatch


So I have a quite common issue. But I did not find the answer I ma seeking on SO or by myself.

I am compiling a package with a c++ extension using numpy headers.

The procedure to create the testing environment is to create an environement from the following conda env file.

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

After this is I install numpy with

pip install numpy==1.21.3

(I also tried installing it from conda.)

And after this I install my project with

pip install . or python -m pip install .

And in my testing environment when I run my tests I have the following error.

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

So first of all, the error is pretty clear so if I upgrade to numpy 1.22.0 it is working.

But what I am trying to understand is why it's says it is compiled against 0xf. I also tried to build without the build isolation and it is the same. I checked my PATH and PYTHONPATH and it seems that there is no conflictinf path. And when I import numpy in my setup.py it says that the version of numpy is 1.21.3

This is the head of my pyproject.toml file.

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

And this is the interesting part of my 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'])

Do you have an hint for me of why I am getting a such error ? And why it is compiled against 0xf ?


Solution

  • I do not know exactly why but changing the py_modules name solved my issue.