SheffieldML / GPy

Gaussian processes framework in python
BSD 3-Clause "New" or "Revised" License
2.01k stars 558 forks source link

Valueerror: numpy.ndarray size changed... when I try to import GPy #936

Open NiranthS opened 3 years ago

NiranthS commented 3 years ago

Hello I installed the latest GPy version using pip install, but when I try importing I have the error: from . import linalg_cython File "GPy/util/linalg_cython.pyx", line 1, in init GPy.util.linalg_cython ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

Some solutions on the internet tell to just try uninstalling and installing NumPy. This changes the NumPy version to the latest one(1.20.x) which is not compatible with TensorFlow. Tensorflow works with only numpy <= 1.19.5

Can you please help me in resolving this so that I can use both TensorFlow and GPy together

Thanks in advance!

sshojiro commented 3 years ago

Hi,

(I'm not a GPy specialist, btw) I encountered the same issue and a solution: https://github.com/SheffieldML/GPy/issues/924#issuecomment-850070387. According to a post on StackOverFlow mentions to reinstall of numpy; however, it did not work for me. Instead, I attempted to install numpy==1.20.0 just in case and it worked as follows.

$ python -c 'import GPy'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\USRE\Anaconda3\envs\picon\lib\site-packages\GPy\__init__.py", line 6, in <module>
    from . import core
  File "C:\Users\USER01\Anaconda3\envs\picon\lib\site-packages\GPy\core\__init__.py", line 49, in <module>
    from .gp import GP
  File "C:\Users\USER01\Anaconda3\envs\picon\lib\site-packages\GPy\core\gp.py", line 8, in <module>
    from .. import likelihoods
  File "C:\Users\USER01\Anaconda3\envs\picon\lib\site-packages\GPy\likelihoods\__init__.py", line 25, in <module>
    from .bernoulli import Bernoulli
  File "C:\Users\USER01\Anaconda3\envs\picon\lib\site-packages\GPy\likelihoods\bernoulli.py", line 5, in <module>
    from ..util.univariate_Gaussian import std_norm_pdf, std_norm_cdf, derivLogCdfNormal, logCdfNormal
  File "C:\Users\USER01\Anaconda3\envs\picon\lib\site-packages\GPy\util\__init__.py", line 11, in <module>
    from . import linalg
  File "C:\Users\USER01\Anaconda3\envs\picon\lib\site-packages\GPy\util\linalg.py", line 15, in <module>
    from . import linalg_cython
  File "GPy/util/linalg_cython.pyx", line 1, in init GPy.util.linalg_cython
    from libc.math cimport sqrt
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

$ pip uninstall numpy -y && pip install numpy==1.20.0
Found existing installation: numpy 1.19.0
Uninstalling numpy-1.19.0:
  Successfully uninstalled numpy-1.19.0
Collecting numpy==1.20.0
  Downloading numpy-1.20.0-cp37-cp37m-win_amd64.whl (13.6 MB)
Installing collected packages: numpy
Successfully installed numpy-1.20.0

$ python -c 'import GPy'

$ python -V
Python 3.7.0
$ pip list | grep GPy
GPy                 1.10.0

Best, SS

NiranthS commented 3 years ago

Thanks for the comment @sshojiro I tried installing numpy 1.20, but it was causing problems in TensorFlow. I think TensorFlow supports numpy <=1.19.5 only

vnmabus commented 2 years ago

This actually is the same as #974. pip compiles GPy against the currently installed NumPy, or the latest one if no NumPy is installed, because the build requirement is wrong. Then a previous (ABI-incompatible) version of NumPy is installed because of the TensorFlow requirement.

This should be fixed by #975. As a workaround, you can try to install an older version of NumPy (such as 1.17), compile GPy against it, and then upgrade the NumPy version.