Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pynbody import error #604

Open
emapple opened this issue Mar 4, 2021 · 3 comments
Open

pynbody import error #604

emapple opened this issue Mar 4, 2021 · 3 comments

Comments

@emapple
Copy link
Contributor

emapple commented Mar 4, 2021

The bug

I recently encountered the error below when trying to import pynbody, as did at least one other pynbody user. Similar issues have recently popped up in other packages (e.g., https://stackoverflow.com/questions/66193302/qiskit-error-numpy-ndarray-size-changed-may-indicate-binary-incompatibility, scikit-learn-contrib/hdbscan#457) since numpy released 1.20.0.

numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

To Reproduce

I am using conda 4.9.2, and created an evironment with the environment.yml file below.
Steps to reproduce:

conda env create -f environment.yml
conda activate ufds
ipython
import pynbody

My setup in the described environment is below. I would have expected numpy to be version 1.20.0 given the new release, but it doesn't seem to be yet available in the default channels.

3.8.8 (default, Feb 24 2021, 21:46:12) 
[GCC 7.3.0]
Linux-2.6.32-696.13.2.el6.x86_64-x86_64-with-glibc2.10
numpy 1.19.2

environment.yml

name: ufds

dependencies:
    - python=3.8
    - ipython
    - jupyter
    - scipy
    - numpy
    - matplotlib
    - pandas
    - nb_conda
    - cython
    - pip:
        - "git+git://github.com/pynbody/pynbody.git"
    - seaborn
    - ipykernel
    - scikit-learn
@emapple
Copy link
Contributor Author

emapple commented Mar 4, 2021

After writing this out I realized I should try with the conda-forge channel, which does have numpy 1.20.0. Adding

channels:
    - conda-forge
    - defaults

to the environment file solves the issue for me (though this may be more of a workaround than a solution, depending on the channels you want to be using).

@MatthieuSchaller
Copy link

MatthieuSchaller commented May 15, 2021

I am facing a similar issue when loading pynbody after having installed it via pip.

That is:

pip3 install pynbody
ipython3

And then:

Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pynbody                                                                                                                                                                                                                                                                    
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-57137f64acd8> in <module>
----> 1 import pynbody

~/.local/lib/python3.8/site-packages/pynbody/__init__.py in <module>
     31 from .configuration import config, config_parser, logger
     32 
---> 33 from . import util, filt, array, family, snapshot
     34 from .snapshot import tipsy, gadget, gadgethdf, ramses, grafic, nchilada, ascii
     35 from . import analysis, halo, derived, bridge, gravity, sph, transformation

~/.local/lib/python3.8/site-packages/pynbody/util.py in <module>
     28 
     29 logger = logging.getLogger('pynbody.util')
---> 30 from ._util import *
     31 
     32 

__init__.pxd in init pynbody._util()

ValueError: numpy.ndarray has the wrong size, try recompiling. Expected 80, got 88

The issue goes away if I upgrade my numpy to 1.20.3 instead of the default 1.19.4 present on my platform.
Updating the pip dependencies might be the solution here.

@apontzen
Copy link
Member

apontzen commented May 15, 2021

This is a built-in 'feature' of pip, I'm afraid, where it builds against a siloed version of numpy instead of the one you actually have installed.

Try passing --no-build-isolation to pip if you don't want to or can't update numpy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants