danielgatis / rembg

Rembg is a tool to remove images background
MIT License
16.46k stars 1.84k forks source link

run rembg error #643

Open youtianhong opened 3 months ago

youtianhong commented 3 months ago

Describe the bug When I run "rembg --help", it report this error as below:

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 "/data/env/digital-human/rembg/bin/rembg", line 5, in from rembg.cli import main File "/data/env/digital-human/rembg/lib/python3.11/site-packages/rembg/init.py", line 5, in from .bg import remove File "/data/env/digital-human/rembg/lib/python3.11/site-packages/rembg/bg.py", line 6, in import onnxruntime as ort File "/data/env/digital-human/rembg/lib/python3.11/site-packages/onnxruntime/init.py", line 23, in from onnxruntime.capi._pybind_state import ExecutionMode # noqa: F401 File "/data/env/digital-human/rembg/lib/python3.11/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in from .onnxruntime_pybind11_state import * # noqa AttributeError: _ARRAY_API not found ImportError: numpy.core.multiarray failed to import

I try to upgrade my numpy to latest version or degrade the numpy version to 1.14.5, but both of them not work. (my numpy version is 2.0.0), I am not sure if some moudle depend low version and some moudle depend high version of numpy ?

  1. unistall numpy
  2. install version 1.14.5 pip install numpy==1.14.5

when I install 1.14.5 version of numpy, it report this issue as below () numpy/core/src/multiarray/scalarapi.c:135:13: warning: ‘PyUnicode_AS_DATA’ is deprecated (declared at /data/env/myproject/rembg/include/python3.11/cpython/unicodeobject.h:702) [-Wdeprecated-declarations] return (void )PyUnicode_AS_DATA(scalar); ^ numpy/core/src/multiarray/scalarapi.c: In function ‘PyArray_DescrFromScalar’: numpy/core/src/multiarray/scalarapi.c:577:13: warning: ‘PyUnicode_GET_DATA_SIZE’ is deprecated (declared at /data/env/myproject/rembg/include/python3.11/cpython/unicodeobject.h:668) [-Wdeprecated-declarations] descr->elsize = PyUnicode_GET_DATA_SIZE(sc); ^ numpy/core/src/multiarray/scalarapi.c: In function ‘PyArray_Scalar’: numpy/core/src/multiarray/scalarapi.c:715:13: warning: ‘ob_shash’ is deprecated (declared at /data/env/myproject/rembg/include/python3.11/cpython/bytesobject.h:7) [-Wdeprecated-declarations] ((PyStringObject )obj)->ob_shash = -1; ^ numpy/core/src/multiarray/scalarapi.c:801:27: error: lvalue required as left operand of assignment Py_SIZE(vobj) = itemsize; ^ error: Command "gcc -pthread -B /data/env/myproject/rembg/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /data/env/myproject/rembg/include -fPIC -O2 -isystem /data/env/myproject/rembg/include -fPIC -DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -Ibuild/src.linux-x86_64-3.1/numpy/core/src/private -Inumpy/core/include -Ibuild/src.linux-x86_64-3.1/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/data/env/myproject/rembg/include/python3.11 -Ibuild/src.linux-x86_64-3.1/numpy/core/src/private -Ibuild/src.linux-x86_64-3.1/numpy/core/src/npymath -Ibuild/src.linux-x86_64-3.1/numpy/core/src/private -Ibuild/src.linux-x86_64-3.1/numpy/core/src/npymath -Ibuild/src.linux-x86_64-3.1/numpy/core/src/private -Ibuild/src.linux-x86_64-3.1/numpy/core/src/npymath -c numpy/core/src/multiarray/scalarapi.c -o build/temp.linux-x86_64-cpython-311/numpy/core/src/multiarray/scalarapi.o -MMD -MF build/temp.linux-x86_64-cpython-311/numpy/core/src/multiarray/scalarapi.o.d" failed with exit status 1 [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for numpy Running setup.py clean for numpy error: subprocess-exited-with-error

× python setup.py clean did not run successfully. │ exit code: 1

and my install env as below: Package Version


aiofiles 23.2.1 aiohttp 3.9.5 aiosignal 1.3.1 altair 5.3.0 annotated-types 0.7.0 anyio 4.4.0 asyncer 0.0.7 attrs 23.2.0 certifi 2024.6.2 charset-normalizer 3.3.2 click 8.1.7 coloredlogs 15.0.1 contourpy 1.2.1 cycler 0.12.1 dnspython 2.6.1 email_validator 2.2.0 fastapi 0.111.0 fastapi-cli 0.0.4 ffmpy 0.3.2 filelock 3.15.3 filetype 1.2.0 flatbuffers 24.3.25 fonttools 4.53.0 frozenlist 1.4.1 fsspec 2024.6.0 gradio 4.36.1 gradio_client 1.0.1 h11 0.14.0 httpcore 1.0.5 httptools 0.6.1 httpx 0.27.0 huggingface-hub 0.23.4 humanfriendly 10.0 idna 3.7 imageio 2.34.1 importlib_resources 6.4.0 Jinja2 3.1.4 jsonschema 4.22.0 jsonschema-specifications 2023.12.1 kiwisolver 1.4.5 lazy_loader 0.4 llvmlite 0.43.0 markdown-it-py 3.0.0 MarkupSafe 2.1.5 matplotlib 3.9.0 mdurl 0.1.2 mpmath 1.3.0 multidict 6.0.5 networkx 3.3 numba 0.60.0 onnxruntime 1.16.3 onnxruntime-gpu 1.16.3 opencv-python-headless 4.10.0.84 orjson 3.10.5 packaging 24.1 pandas 2.2.2 pillow 10.3.0 pip 24.0 platformdirs 4.2.2 pooch 1.8.2 protobuf 5.27.1 pydantic 2.7.4 pydantic_core 2.18.4 pydub 0.25.1 Pygments 2.18.0 PyMatting 1.1.12 pyparsing 3.1.2 python-dateutil 2.9.0.post0 python-dotenv 1.0.1 python-multipart 0.0.9 pytz 2024.1 PyYAML 6.0.1 referencing 0.35.1 rembg 2.0.57 requests 2.32.3 rich 13.7.1 rpds-py 0.18.1 ruff 0.4.10 scikit-image 0.24.0 scipy 1.13.1 semantic-version 2.10.0 setuptools 69.5.1 shellingham 1.5.4 six 1.16.0 sniffio 1.3.1 starlette 0.37.2 sympy 1.12.1 tifffile 2024.6.18 tomlkit 0.12.0 toolz 0.12.1 tqdm 4.66.4 typer 0.12.3 typing_extensions 4.12.2 tzdata 2024.1 ujson 5.10.0 urllib3 2.2.2 uvicorn 0.30.1 uvloop 0.19.0 watchdog 4.0.1 watchfiles 0.22.0 websockets 11.0.3 wheel 0.43.0 yarl 1.9.4

joynahid commented 3 months ago

This solved my issue:

pip install numpy==1.26.4

But, something is messed up in rembg.

youtianhong commented 3 months ago

This solved my issue:

pip install numpy==1.26.4

But, something is messed up in rembg.

Thanks joynahid so much! This works for me.

epuig83 commented 2 months ago

This solved my issue:

pip install numpy==1.26.4

But, something is messed up in rembg.

Thanks! Same problem here, solution worked for me as well.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

JagadeepSai commented 1 month ago

Any update on this other than reverting back numpy? The below issue is shown for me, when updated to latest packages.

 File "/home/user/venv/lib/python3.10/site-packages/rembg/__init__.py", line 5, in <module>
    from .bg import remove
  File "/home/user/venv/lib/python3.10/site-packages/rembg/bg.py", line 6, in <module>
    import onnxruntime as ort
  File "/home/user/venv/lib/python3.10/site-packages/onnxruntime/__init__.py", line 23, in <module>
    from onnxruntime.capi._pybind_state import ExecutionMode  # noqa: F401
  File "/home/user/venv/lib/python3.10/site-packages/onnxruntime/capi/_pybind_state.py", line 32, in <module>
    from .onnxruntime_pybind11_state import *  # noqa
AttributeError: _ARRAY_API not found
ImportError: numpy.core.multiarray failed to import

The above exception was the direct cause of the following exception:

SystemError: <built-in function __import__> returned a result with an exception set
xiaozhou437 commented 1 month ago

Error occurred when executing RemBGSession+:

cannot import name 'new_session' from 'rembg'

xiaozhou437 commented 1 month ago

执行 RemBGSession+ 时出错:

无法从“rembg”导入名称“new_session”

求解答

Gabrock94 commented 3 weeks ago

For me, this solved the issue

python -m pip install coloredlogs flatbuffers numpy packaging protobuf sympy
python -m pip install -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ ort_nightly

see https://github.com/microsoft/onnxruntime/issues/21063