nadermx / backgroundremover

Background Remover lets you Remove Background from images and video using AI with a simple command line interface that is free and open source.
https://www.backgroundremoverai.com
MIT License
6.7k stars 558 forks source link

Installation succeeds, running fails #14

Closed av01d closed 3 years ago

av01d commented 3 years ago

After successfully installing backroundremover, I am running into the following issue when running it:

[arjan@cure:bgRemove]% backgroundremover -i 'input.jpg' 'out.png'
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/arjan/.local/lib/python3.7/site-packages/pymatting_aot/cc.py", line 36, in <module>
    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/arjan/.local/bin/backgroundremover", line 5, in <module>
    from backgroundremover.cmd.cli import main
  File "/home/arjan/.local/lib/python3.7/site-packages/backgroundremover/cmd/cli.py", line 5, in <module>
    from .. import utilities
  File "/home/arjan/.local/lib/python3.7/site-packages/backgroundremover/utilities.py", line 10, in <module>
    from .bg import DEVICE, Net, iter_frames, remove_many
  File "/home/arjan/.local/lib/python3.7/site-packages/backgroundremover/bg.py", line 6, in <module>
    from pymatting.alpha.estimate_alpha_cf import estimate_alpha_cf
  File "/home/arjan/.local/lib/python3.7/site-packages/pymatting/__init__.py", line 2, in <module>
    import pymatting_aot.cc
  File "/home/arjan/.local/lib/python3.7/site-packages/pymatting_aot/cc.py", line 54, in <module>
    compile_modules()
  File "/home/arjan/.local/lib/python3.7/site-packages/pymatting_aot/cc.py", line 8, in compile_modules
    cc = CC("aot")
  File "/home/arjan/.local/lib/python3.7/site-packages/numba/pycc/cc.py", line 65, in __init__
    self._toolchain = Toolchain()
  File "/home/arjan/.local/lib/python3.7/site-packages/numba/pycc/platform.py", line 78, in __init__
    self._raise_external_compiler_error()
  File "/home/arjan/.local/lib/python3.7/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

Any idea? I'm on a Debian 10 system. gcc is installed.

nadermx commented 3 years ago

I've only tested this with ubuntu. Did you install python3.7-dev?

av01d commented 3 years ago

I've only tested this with ubuntu. Did you install python3.7-dev?

Yes, it's there:

[arjan@cure:bgRemove]% sudo apt-get install python3.7-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3.7-dev is already the newest version (3.7.3-2+deb10u3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
nadermx commented 3 years ago

I think you need both, python3-dev and python3.7-dev

nadermx commented 3 years ago

and do you have it running in a virtual enviroment, I think there was another user who had issues due to depenciy conflict

av01d commented 3 years ago

I think you need both, python3-dev and python3.7-dev

I already have both of them:

[arjan@cure:bgRemove]% sudo apt-get install python3-dev python3.7-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-dev is already the newest version (3.7.3-1).
python3.7-dev is already the newest version (3.7.3-2+deb10u3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
av01d commented 3 years ago

and do you have it running in a virtual enviroment, I think there was another user who had issues due to depenciy conflict

I am not. I am on a terminal directly on the server.

nadermx commented 3 years ago

Can you try installing it into a virtual enviroment, and trying it that way?

av01d commented 3 years ago

Can you try installing it into a virtual enviroment, and trying it that way?

No, I can't. I'll keep trying, thanks for your help!

nadermx commented 3 years ago

I saw these two things that might be, try conda install gcc_linux-64 gxx_linux-64 or it seems it could be something I saw that maybe this could also be a solution.

This is likely an issue with Numba. It should probably recompile old modules or not crash when importing them.

Temporary fix

Locate the ahead-of-time compiled module and delete it. A new import will trigger a recompilation. In my case, the file was located at ~/miniconda3/lib/python3.7/site-packages/pymatting_aot/aot.cpython-37m-x86_64-linux-gnu.so
nadermx commented 3 years ago

and or lastly try apt-get install -y build-essential

av01d commented 3 years ago

I found a fix, albeit a clumsy one. In file /home/arjan/.local/lib/python3.7/site-packages/numba/pycc/platform.py, I changed function def _check_external_compiler(): a bit. It now reads:

def _check_external_compiler():
    # see if the external compiler bound in numpy.distutil is present
    # and working
    return True # FIX: return True immediately

Now it all works!

av01d commented 3 years ago

and or lastly try apt-get install -y build-essential

Yeah, tried that already, turns out I had it installed at latest version already.

nadermx commented 3 years ago

So glad to hear! If there is any other problem let me know and reopen this issue.