sony/nnabla

cannot import nnabla in `numpy==1.21.4` and `nnabla>=1.29.0`

IsaraAomi opened this issue ยท 9 comments

  • python: 3.8.10
    • installed by pyenv: 2.3.4-14-g093d0b3a
  • I found that I cannot import nnabla in the environment of numpy==1.21.4 and nnabla==1.29.0 or 1.30.0.
Experiment log
isara@SPICA:~$ pip list
Package    Version
---------- -------
pip        22.2.2
setuptools 65.3.0
isara@SPICA:~$ pip install numpy==1.21.4
...
...
isara@SPICA:~$ pip install nnabla==1.29.0
...
...
isara@SPICA:~$ pip list
Package         Version
--------------- -------
boto3           1.24.76
botocore        1.27.76
configparser    5.3.0
contextlib2     21.6.0
Cython          0.29.32
h5py            3.7.0
imageio         2.22.0
jmespath        1.0.1
nnabla          1.29.0
numpy           1.21.4
Pillow          9.2.0
pip             22.2.2
protobuf        3.19.4
python-dateutil 2.8.2
PyYAML          6.0
s3transfer      0.6.0
scipy           1.9.1
setuptools      65.3.0
six             1.16.0
tqdm            4.64.1
urllib3         1.26.12
isara@SPICA:~$ python
Python 3.8.10 (default, Sep 20 2022, 10:17:21)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nnabla
2022-09-20 10:53:14,554 [nnabla][INFO]: Initializing CPU extension...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/isara/.pyenv/versions/3.8.10/lib/python3.8/site-packages/nnabla/__init__.py", line 32, in <module>
    from .variable import Variable, Context
  File "/home/isara/.pyenv/versions/3.8.10/lib/python3.8/site-packages/nnabla/variable.py", line 17, in <module>
    from ._variable import Context
  File "_variable.pyx", line 1, in init nnabla._variable
  File "_nd_array.pyx", line 1, in init nnabla._nd_array
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
>>> exit()
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/isara/.pyenv/versions/3.8.10/lib/python3.8/site-packages/nnabla/__init__.py", line 32, in <module>
    from .variable import Variable, Context
  File "/home/isara/.pyenv/versions/3.8.10/lib/python3.8/site-packages/nnabla/variable.py", line 17, in <module>
    from ._variable import Context
  File "_variable.pyx", line 1, in init nnabla._variable
  File "_nd_array.pyx", line 1, in init nnabla._nd_array
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
isara@SPICA:~$
  • I got the same error in nnabla==1.30.0.

  • After that, if numpy's version is upgraded to 1.22.4, I can import nnabla.
Experiment log
isara@SPICA:~$ pip list
Package    Version
---------- -------
pip        22.2.2
setuptools 65.3.0
isara@SPICA:~$ pip install numpy==1.22.4
...
...
isara@SPICA:~$ pip install nnabla==1.29.0
...
...
isara@SPICA:~$ pip list
Package         Version
--------------- -------
boto3           1.24.76
botocore        1.27.76
configparser    5.3.0
contextlib2     21.6.0
Cython          0.29.32
h5py            3.7.0
imageio         2.22.0
jmespath        1.0.1
nnabla          1.29.0
numpy           1.22.4
Pillow          9.2.0
pip             22.2.2
protobuf        3.19.4
python-dateutil 2.8.2
PyYAML          6.0
s3transfer      0.6.0
scipy           1.9.1
setuptools      65.3.0
six             1.16.0
tqdm            4.64.1
urllib3         1.26.12
isara@SPICA:~$ python
Python 3.8.10 (default, Sep 20 2022, 10:17:21)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nnabla
2022-09-20 10:59:24,297 [nnabla][INFO]: Initializing CPU extension...
>>> exit()
isara@SPICA:~$
  • I got the same result in nnabla==1.30.0.
  • But, I have not tried the smallest version of numpy that eliminates the error.

  • I would like you to try to reproduce this problem.
  • Then, if there is a problem, please update the required version of numpy.
    • - numpy [required: >=1.20.0, installed: 1.22.4] according to pipdeptree.

Thank you for reporting.
I think we are running nnabla with latest numpy, so we'll try to reproduce your issue.

Ah, I misunderstand the version, it is numpy 1.21.x... All right, your investigation might be correct.
We will check and add requirement for pip.

@TomonobuTsujikawa I'm experiencing a similar issue with nnabla 1.32.0. I'm using Windows 10, Python 3.8, and whatever numpy comes with pip install nnabla:

> python
Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import nnabla
2023-01-06 18:28:44,394 [nnabla][INFO]: Initializing CPU extension...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Jeffrey\Documents\Dev\env\lib\site-packages\nnabla\__init__.py", line 44, in <module>
    from .grad import grad
  File "C:\Users\Jeffrey\Documents\Dev\env\lib\site-packages\nnabla\grad.py", line 20, in <module>
    import nnabla.functions as F
  File "C:\Users\Jeffrey\Documents\Dev\env\lib\site-packages\nnabla\functions.py", line 18, in <module>
    from . import dtypes
  File "C:\Users\Jeffrey\Documents\Dev\env\lib\site-packages\nnabla\dtypes.py", line 19, in <module>
    np_dtpye_to_int[np.bool] = 0
  File "C:\Users\Jeffrey\Documents\Dev\env\lib\site-packages\numpy\__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'bool'

If I use an older numpy like v1.22.4:

>>> import nnabla
2023-01-06 18:33:53,065 [nnabla][INFO]: Initializing CPU extension...
Traceback (most recent call last):
  File "__init__.pxd", line 943, in numpy.import_array
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Jeffrey\Documents\Dev\env\lib\site-packages\nnabla\__init__.py", line 32, in <module>
    from .variable import Variable, Context
  File "C:\Users\Jeffrey\Documents\Dev\env\lib\site-packages\nnabla\variable.py", line 17, in <module>
    from ._variable import Context
  File "_variable.pyx", line 1, in init nnabla._variable
  File "_nd_array.pyx", line 32, in init nnabla._nd_array
  File "__init__.pxd", line 945, in numpy.import_array
ImportError: numpy.core.multiarray failed to import

@JeffreyCA
Sorry for inconvenience, we could not include the fix in v1.32.0.
Now we fixed this numpy incompatibility issue in master branch by #1139
And, it will be released in next version.

We're sorry for waiting long time for this numpy issue.

If you face these errors, please downgrade (or upgrade) numpy version until a new version (v1.33.0) is released.
Here is the way to install appropriate numpy for nnabla v1.32.x:

pip install -U numpy==1.23.5

After nnabla v1.33.0, the appropriate numpy version will be installed by automatically.

nnabla v1.33.0 has been released, so we hope this issue has now been resolved.

Sorry for the late reply.
I have confirmed that the problem has been resolved in v1.33.0.
Thank you so much.

sorry, I face the similar issue when I am doing with the latest version 1.35.1, I cannot import nnabla in numpy==1.23.5 @TomonobuTsujikawa

We have already taken measures to address this issue by #1139
The latest nnabla (v1.35.1) will install numpy v1.23.5 normally, so it should work.

Here is my instruction, and it seems to work correctly on my environment. Could you please check?

$ python --version
Python 3.8.10
$ pip --version
pip 20.0.2 from /tmp/a/test/lib/python3.8/site-packages/pip (python 3.8)
$ pip install -U pip
(snip)
$ pip --version
pip 23.1.2 from /tmp/a/test/lib/python3.8/site-packages/pip (python 3.8)

$ pip install nnabla
(snip)
$ python -c "import nnabla"
2023-06-09 10:20:41,239 [nnabla][INFO]: Initializing CPU extension...

$ pip list|grep -e numpy -e nnabla
nnabla          1.35.1
numpy           1.23.5