Python bindings: ValueError: numpy.ndarray size changed

I am trying to get the python binding for precice running and upon installing I am getting ValueError (described below). I previously had anaconda installed and using its python3.8.10 and libprecice2.2.0 but now I have removed anaconda and updated precice and still I am facing similar issue.

  • preCICE version: libprecice2_2.2.1
  • Operating system or platform (e.g. “Ubuntu 20.04”)
  • Installation method: apt, pip3
  • Dependency versions: python3.8.10, numpy1.17.4
pip3 install --user pyprecice
Processing /home/mansari/.cache/pip/wheels/53/96/9c/871e18d16d08e5d3a1eedaf5bbe74d115291e44c67c7379f70/pyprecice-
Requirement already satisfied: mpi4py in /home/mansari/.local/lib/python3.8/site-packages (from pyprecice) (3.0.3)
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from pyprecice) (1.17.4)
ERROR: fenicsprecice 1.1.0+10.gb248cf0 requires scipy, which is not installed.
Installing collected packages: pyprecice
Successfully installed pyprecice-

**********$ python3
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import precice
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mansari/.local/lib/python3.8/site-packages/precice/", line 4, in <module>
    from cyprecice import Interface, action_read_iteration_checkpoint, action_write_iteration_checkpoint, action_write_initial_data, get_version_information
  File "cyprecice/cyprecice.pyx", line 1, in init cyprecice
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

After upgrading the numpy version to 1.20 (same python version) it started working. Is this an issue with the bindings or did I do something wrong before?

I tried downgrading my NumPy to 1.7.4, but the installation keeps working, so maybe this is not the issue.

(FYI, I was talking with @arslansadiq when opening this thread)

I just tried on my machine with Ubuntu 20.04 and NumPy 1.17.4 and it worked without problems. Did you try to install SciPy to see if this makes a difference? I am curious since there is an error about the SciPy dependency. Which version of pip are you using? I am currently at 21.2.2.

Hi @arslansadiq

The following line is indeed puzzling, because it is in fact it is pointing to an error from the package fenicsprecice which is not even what you are installing here.

By chance do you have fenicsprecice also installed? And as @ajaust mentioned have you installed scipy?

For testing I removed scipy (python3-scipy) from my machine and it still works.

> pip install --user pyprecice
Collecting pyprecice
  Using cached pyprecice-
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from pyprecice) (1.17.4)
Requirement already satisfied: mpi4py in /usr/lib/python3/dist-packages (from pyprecice) (3.0.3)
Installing collected packages: pyprecice
Successfully installed pyprecice-

It both worked with versions 21.2.3 and 21.2.2 of pip for me.

Maybe you could tell us which version of pip you use with pip --version .

Besides that I could see that this error is still a side effect of your Conda installation. Are there any Conda leftovers on the system? Maybe some paths are still set? Did you open a new terminal after removing Conda and did you clean up your .bashrc or .bash_profile? Conda normally offers to add some environment variables in one of these files.