ros-perception / vision_opencv

Apache License 2.0
560 stars 604 forks source link

Numpy 2.0 support #535

Open nikhilpodila opened 4 months ago

nikhilpodila commented 4 months ago

Similar to this error previously in opencv, I get the following error when importing cv-bridge:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/opt/ros/humble/lib/my_driver/my_driver_node", line 33, in <module>
    sys.exit(load_entry_point('my-driver==0.1.0', 'console_scripts', 'my_driver_node')())
  File "/opt/ros/humble/lib/my_driver/my_driver_node", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/ros/humble/lib/python3.10/site-packages/my_driver/my_driver_node.py", line 8, in <module>
    from cv_bridge import CvBridge
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/cv_bridge/__init__.py", line 6, in <module>
    from cv_bridge.boost.cv_bridge_boost import cvtColorForDisplay, getCvType
AttributeError: _ARRAY_API not found

It looks like cv-bridge installed via apt or pip is not yet built with numpy 2.0. Is the support for numpy 2.0 coming soon?

23pointsNorth commented 4 months ago

From what I can see, the package relies on python-numpy in package.xml

Checking the version

apt search python3-numpy
Sorting... Done
Full Text Search... Done
python3-numpy/jammy-updates,jammy-security,now 1:1.21.5-1ubuntu22.04.1 amd64 [installed,automatic]
  Fast array facility to the Python 3 language

Returns numpy at 1.21.5

So from what I can see we need to also submit a request to bump the numpy version in apt.

ijnek commented 6 days ago

Currently, Ubuntu Jammy and Ubuntu Noble use NumPy 1.21 and 1.26 as their default binary versions, so there hasn't been a strong push to adopt NumPy 2 yet. However, pull requests to add support are always welcome.