ImportError: numpy.core.multiarray failed to import

I have build the bpy module in my site-package. But when I import the bpy, error occurs:

$ python example/render.py > output/render.log

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 "/home/xzx/Project/RTCC/example/render.py", line 1, in <module>
    import bpy
AttributeError: _ARRAY_API not found
ImportError: numpy.core.multiarray failed to import

The Numpy version used to compile and run is 2.0.0.

hard to say without any more information, however given you have the right python version (3.11) you can just grab blender using pip from pypi

https://pypi.org/project/bpy/

I have tried this method, but it doesn’t work.

In the install messages of pip install bpy numpy 2.2.1 is being detected and used. The bpy doesn’t (but should) have numpy<2.0.0 as a dependency, so you’ll just have to create an environment that limits numpy to <2.0.0 and then when bpy imports it during your script it should be fine.

Thank you! I fixed this problem with pip install numpy==1.26.