rembg icon indicating copy to clipboard operation
rembg copied to clipboard

Error ModuleNotFoundError: No module named 'pymatting_aot.aot'

Open arnold408 opened this issue 6 years ago • 24 comments

Hello, I have centos 8 server.

This is the error after running the command rembg -o input_image output_image

Failed to import ahead-of-time-compiled modules. This is expected on first import. Compiling modules and trying again (this might take a minute). Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/pymatting_aot/cc.py", line 21, in import pymatting_aot.aot ModuleNotFoundError: No module named 'pymatting_aot.aot'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/bin/rembg", line 5, in from rembg.cmd.cli import main File "/usr/local/lib/python3.8/site-packages/rembg/cmd/cli.py", line 7, in from ..bg import remove File "/usr/local/lib/python3.8/site-packages/rembg/bg.py", line 6, in from pymatting.alpha.estimate_alpha_cf import estimate_alpha_cf File "/usr/local/lib/python3.8/site-packages/pymatting/init.py", line 2, in import pymatting_aot.cc File "/usr/local/lib/python3.8/site-packages/pymatting_aot/cc.py", line 28, in compile_modules() File "/usr/local/lib/python3.8/site-packages/pymatting_aot/cc.py", line 16, in compile_modules cc.compile() File "/usr/local/lib64/python3.8/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock return func(*args, **kwargs) File "/usr/local/lib64/python3.8/site-packages/numba/pycc/cc.py", line 217, in compile objects += self._compile_mixins(build_dir) File "/usr/local/lib64/python3.8/site-packages/numba/pycc/cc.py", line 187, in _compile_mixins objects = self._toolchain.compile_objects(sources, build_dir, File "/usr/local/lib64/python3.8/site-packages/numba/pycc/platform.py", line 137, in compile_objects objects = self._compiler.compile(sources, File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/ccompiler.py", line 90, in m = lambda self, *args, **kw: func(self, *args, **kw) File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/ccompiler.py", line 356, in CCompiler_compile pool.map(single_compile, build_items) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/usr/lib64/python3.8/multiprocessing/pool.py", line 768, in get raise self._value File "/usr/lib64/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 48, in mapstar return list(map(*args)) File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/ccompiler.py", line 321, in single_compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/ccompiler.py", line 90, in m = lambda self, *args, **kw: func(self, *args, **kw) File "/usr/local/lib64/python3.8/site-packages/numpy/distutils/unixccompiler.py", line 54, in UnixCCompiler__compile raise CompileError(msg) distutils.errors.CompileError: Command "gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPYCC_MODULE_NAME=aot -DPYCC_USE_NRT=1 -I/usr/include/python3.8 -I/usr/local/lib64/python3.8/site-packages/numpy/core/include -c /usr/local/lib64/python3.8/site-packages/numba/cext/utils.c -o /tmp/pycc-build-aot-gz0f8q5m/usr/local/lib64/python3.8/site-packages/numba/cext/utils.o" failed with exit status 1

This is the command I have used to install rembg

python3.8 -m pip install --upgrade pip

[root@ ]# python3.8 -m pip install rembg

Processing /root/.cache/pip/wheels/c4/52/be/f93ed10eb3209e691a9226d0ba337172ef19e38a0014892198/rembg-1.0.15-cp38-none-any.whl Requirement already satisfied: pillow==8.0.1 in /usr/local/lib64/python3.8/site-packages (from rembg) (8.0.1) Requirement already satisfied: numpy==1.19.4 in /usr/local/lib64/python3.8/site-packages (from rembg) (1.19.4) Requirement already satisfied: requests==2.24.0 in /usr/local/lib/python3.8/site-packages (from rembg) (2.24.0) Requirement already satisfied: scipy==1.5.4 in /usr/local/lib64/python3.8/site-packages (from rembg) (1.5.4) Requirement already satisfied: scikit-image==0.17.2 in /usr/local/lib64/python3.8/site-packages (from rembg) (0.17.2) Requirement already satisfied: waitress==1.4.4 in /usr/local/lib/python3.8/site-packages (from rembg) (1.4.4) Requirement already satisfied: pymatting==1.1.1 in /usr/local/lib/python3.8/site-packages (from rembg) (1.1.1) Requirement already satisfied: tqdm==4.51.0 in /usr/local/lib/python3.8/site-packages (from rembg) (4.51.0) Requirement already satisfied: flask==1.1.2 in /usr/local/lib/python3.8/site-packages (from rembg) (1.1.2) Requirement already satisfied: torchvision==0.8.1 in /usr/local/lib64/python3.8/site-packages (from rembg) (0.8.1) Requirement already satisfied: torch==1.7.0 in /usr/local/lib64/python3.8/site-packages (from rembg) (1.7.0) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.8/site-packages (from requests==2.24.0->rembg) (1.25.11) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.8/site-packages (from requests==2.24.0->rembg) (2020.11.8) Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.8/site-packages (from requests==2.24.0->rembg) (3.0.4) Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.8/site-packages (from requests==2.24.0->rembg) (2.10) Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.8/site-packages (from scikit-image==0.17.2->rembg) (2020.10.1) Requirement already satisfied: matplotlib!=3.0.0,>=2.0.0 in /usr/local/lib64/python3.8/site-packages (from scikit-image==0.17.2->rembg) (3.3.3) Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.8/site-packages (from scikit-image==0.17.2->rembg) (2.5) Requirement already satisfied: imageio>=2.3.0 in /usr/local/lib/python3.8/site-packages (from scikit-image==0.17.2->rembg) (2.9.0) Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib64/python3.8/site-packages (from scikit-image==0.17.2->rembg) (1.1.1) Requirement already satisfied: numba!=0.49.0 in /usr/local/lib64/python3.8/site-packages (from pymatting==1.1.1->rembg) (0.51.2) Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python3.8/site-packages (from flask==1.1.2->rembg) (2.11.2) Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.8/site-packages (from flask==1.1.2->rembg) (7.1.2) Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.8/site-packages (from flask==1.1.2->rembg) (1.1.0) Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python3.8/site-packages (from flask==1.1.2->rembg) (1.0.1) Requirement already satisfied: dataclasses in /usr/local/lib/python3.8/site-packages (from torch==1.7.0->rembg) (0.6) Requirement already satisfied: future in /usr/local/lib/python3.8/site-packages (from torch==1.7.0->rembg) (0.18.2) Requirement already satisfied: typing-extensions in /usr/local/lib/python3.8/site-packages (from torch==1.7.0->rembg) (3.7.4.3) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib64/python3.8/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (1.3.1) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /usr/local/lib/python3.8/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (2.4.7) Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.8/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (2.8.1) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (0.10.0) Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.8/site-packages (from networkx>=2.0->scikit-image==0.17.2->rembg) (4.4.2) Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /usr/local/lib64/python3.8/site-packages (from numba!=0.49.0->pymatting==1.1.1->rembg) (0.34.0) Requirement already satisfied: setuptools in /usr/lib/python3.8/site-packages (from numba!=0.49.0->pymatting==1.1.1->rembg) (41.6.0) Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib64/python3.8/site-packages (from Jinja2>=2.10.1->flask==1.1.2->rembg) (1.1.1) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.8/site-packages (from python-dateutil>=2.1->matplotlib!=3.0.0,>=2.0.0->scikit-image==0.17.2->rembg) (1.15.0) Installing collected packages: rembg Successfully installed rembg-1.0.15

Please suggest

arnold408 avatar Nov 13 '20 06:11 arnold408

same here..

eness avatar Nov 14 '20 10:11 eness

I had error when try rembg -o input Failed to import ahead-of-time-compiled modules. This is expected on first import. Compiling modules and trying again (this might take a minute). Traceback (most recent call last): File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/pymatting_aot/cc.py", line 21, in import pymatting_aot.aot ModuleNotFoundError: No module named 'pymatting_aot.aot'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/distutils/unixccompiler.py", line 50, in UnixCCompiler__compile self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + deps + File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/distutils/ccompiler.py", line 90, in m = lambda self, *args, **kw: func(self, *args, **kw) File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/distutils/ccompiler.py", line 173, in CCompiler_spawn raise DistutilsExecError('Command "%s" failed with exit status %d%s' % distutils.errors.DistutilsExecError: Command "x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYCC_MODULE_NAME=aot -DPYCC_USE_NRT=1 -I/home/tony/PycharmProjects/rem/venv/include -I/usr/include/python3.8 -I/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/core/include -c /home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numba/pycc/modulemixin.c -o /tmp/pycc-build-aot-myc0q035/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numba/pycc/modulemixin.o" failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/tony/PycharmProjects/rem/venv/bin/rembg", line 5, in from rembg.cmd.cli import main File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/rembg/cmd/cli.py", line 8, in from ..bg import remove File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/rembg/bg.py", line 6, in from pymatting.alpha.estimate_alpha_cf import estimate_alpha_cf File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/pymatting/init.py", line 2, in import pymatting_aot.cc File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/pymatting_aot/cc.py", line 28, in compile_modules() File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/pymatting_aot/cc.py", line 16, in compile_modules cc.compile() File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numba/core/compiler_lock.py", line 32, in _acquire_compile_lock return func(*args, **kwargs) File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numba/pycc/cc.py", line 217, in compile objects += self._compile_mixins(build_dir) File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numba/pycc/cc.py", line 187, in _compile_mixins objects = self._toolchain.compile_objects(sources, build_dir, File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numba/pycc/platform.py", line 137, in compile_objects objects = self._compiler.compile(sources, File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/distutils/ccompiler.py", line 90, in m = lambda self, *args, **kw: func(self, *args, **kw) File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/distutils/ccompiler.py", line 361, in CCompiler_compile single_compile(o) File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/distutils/ccompiler.py", line 321, in single_compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/distutils/ccompiler.py", line 90, in m = lambda self, *args, **kw: func(self, *args, **kw) File "/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/distutils/unixccompiler.py", line 54, in UnixCCompiler__compile raise CompileError(msg) distutils.errors.CompileError: Command "x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYCC_MODULE_NAME=aot -DPYCC_USE_NRT=1 -I/home/tony/PycharmProjects/rem/venv/include -I/usr/include/python3.8 -I/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numpy/core/include -c /home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numba/pycc/modulemixin.c -o /tmp/pycc-build-aot-myc0q035/home/tony/PycharmProjects/rem/venv/lib/python3.8/site-packages/numba/pycc/modulemixin.o" failed with exit status 1

please suggest

VyVu avatar Nov 19 '20 07:11 VyVu

you need to install the python3-dev

apt-get install -y python3-dev

danielgatis avatar Nov 21 '20 13:11 danielgatis

[solved] sudo dnf install gcc-c++, after it works fine. same there. Fedora 33, python-devel installed. venv with python 3.8.

$ rembg Failed to import ahead-of-time-compiled modules. This is expected on first import. Compiling modules and trying again (this might take a minute). Traceback (most recent call last): File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/pymatting_aot/cc.py", line 21, in import pymatting_aot.aot ModuleNotFoundError: No module named 'pymatting_aot.aot'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/sav/pytest/envrembg/bin/rembg", line 5, in from rembg.cmd.cli import main File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/rembg/cmd/cli.py", line 8, in from ..bg import remove File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/rembg/bg.py", line 6, in from pymatting.alpha.estimate_alpha_cf import estimate_alpha_cf File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/pymatting/init.py", line 2, in import pymatting_aot.cc File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/pymatting_aot/cc.py", line 28, in compile_modules() File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/pymatting_aot/cc.py", line 6, in compile_modules cc = CC("aot") File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/numba/pycc/cc.py", line 65, in init self._toolchain = Toolchain() File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/numba/pycc/platform.py", line 78, in init self._raise_external_compiler_error() File "/home/sav/pytest/envrembg/lib64/python3.8/site-packages/numba/pycc/platform.py", line 121, in _raise_external_compiler_error raise RuntimeError(msg) RuntimeError: Attempted to compile AOT function without the compiler used by numpy.distutils present. If using conda try:

#> conda install gcc_linux-64 gxx_linux-64

vlsav avatar Nov 21 '20 19:11 vlsav

you need to install the python3-dev

apt-get install -y python3-dev

thanks, I solved it

VyVu avatar Nov 23 '20 04:11 VyVu

you need to install the python3-dev

apt-get install -y python3-dev

It's not working on windows

umairsajid0017 avatar Dec 12 '20 01:12 umairsajid0017

In my case I still had to install an compiler: && apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends manpages-dev

Cold-A-Muse avatar Jan 12 '21 02:01 Cold-A-Muse

Please let me know How to fix this in windows?

sanind avatar Jan 22 '21 16:01 sanind

I was able to fix it on ubuntu with this command:

apt-get install python3.8-dev

avaleriani avatar Feb 04 '21 12:02 avaleriani

Please let me know How to fix this in windows?

Install “C++ build tools” on windows. Need 6GB free disk space

Download from visualstudio site below : https://visualstudio.microsoft.com/

Step1: download the "Visualstudio BuildTools" , a small file installer
Step2 : run this install and select “C++ build tools” , install it

jinwyp avatar Feb 05 '21 14:02 jinwyp

apt-get install -y build-essential also fixes the issue. Tested when building a Docker image on top of python:3.8-slim-buster.

tuomastik avatar Feb 10 '21 06:02 tuomastik

hi friends, i have the same error in windows, how can i fix it? my python version is 3.8.1 and i have installed C++ Build tool 14.0

JackingHu avatar Feb 20 '21 09:02 JackingHu

hi friends, i have the same error in windows, how can i fix it? my python version is 3.8.1 and i have installed C++ Build tool 14.0

install python 3.8.7 on windows

jinwyp avatar Feb 28 '21 20:02 jinwyp

I recently had the same issue and none of the solutions here helped.

I was trying to clone a server and run a test script after installing all prereqs and this is where I encountered this issues.

Finally, I have found that the interpreter was somehow cutting short the first-install compile operation.

The solution was to open the python interpreter and import both rembg and rembg.bg and thus everything was compiled as intended and it worked.

petremihaivalentin avatar Mar 19 '21 14:03 petremihaivalentin

I am using rh-python38 on CentOS 7

This solved my problem:

yum install rh-python38-python-devel

louislam avatar Mar 21 '21 08:03 louislam

None of above solves the issue for me, tried them all. WSL ubuntu 20.04. python 3.8

did update, upgrade. python3-dev already installed same with build-essential

Boffice avatar Sep 02 '21 15:09 Boffice

I've also tried all above solutions for window but none of the solutions works. Any help would be appreciated. Thanks.

Python\Python39\lib\site-packages\pymatting_aot\cc.py", line 36, in <module>
    import pymatting_aot.aot
ModuleNotFoundError: No module named 'pymatting_aot.aot'

uvtechnolab-git avatar Oct 03 '21 19:10 uvtechnolab-git

None of above solves the issue for me, tried them all. WSL ubuntu 20.04. python 3.8

did update, upgrade. python3-dev already installed same with build-essential

me too

badboy-tian avatar Oct 11 '21 08:10 badboy-tian

None of above solves the issue for me, tried them all. WSL ubuntu 20.04. python 3.8

did update, upgrade. python3-dev already installed same with build-essential

me too

I managed to make it work for me https://github.com/danielgatis/rembg/issues/133#issuecomment-912441274

Boffice avatar Oct 11 '21 09:10 Boffice

Same issue in ubuntu when installing rembg as a regular user. When switching to a sudoer and installing everything as root, everything installs fine (when fixing numpy==1.20.0)

Which makes me wonder whether this is a bindings issue.

vtrikoupis avatar Oct 14 '21 07:10 vtrikoupis