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.86k stars 575 forks source link

Can't run bg remover on windows, "process cannot access the file" #53

Closed 343intact closed 1 year ago

343intact commented 1 year ago

PS D:\Programs\backgroundremover-main> python -m backgroundremover.cmd.cli -i "D:\Downloads\Telegram\photo_2023-01-11_14-01-01.jpg" -a -ae 15 -o "meow.png" meow.png downloading part 1 of u2net finished downloading part 1 of u2net downloading part 2 of u2net finished downloading part 2 of u2net downloading part 3 of u2net finished downloading part 3 of u2net downloading part 4 of u2net finished downloading part 4 of u2net Traceback (most recent call last): File "C:\Users\aboba\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\aboba\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\Programs\backgroundremover-main\backgroundremover\cmd\cli.py", line 253, in main() File "D:\Programs\backgroundremover-main\backgroundremover\cmd\cli.py", line 239, in main remove( File "D:\Programs\backgroundremover-main\backgroundremover\bg.py", line 179, in remove model = get_model(model_name) File "D:\Programs\backgroundremover-main\backgroundremover\bg.py", line 167, in get_model return detect.load_model(model_name="u2net") File "D:\Programs\backgroundremover-main\backgroundremover\u2net\detect.py", line 55, in load_model utilities.download_files_from_github( File "D:\Programs\backgroundremover-main\backgroundremover\utilities.py", line 347, in download_files_from_github os.remove(part.name) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\aboba\AppData\Local\Temp\tmpq378j2qx' PS D:\Programs\backgroundremover-main> python -m backgroundremover.cmd.cli -i "D:\Downloads\Telegram\photo_2023-01-11_14-01-01.jpg" -o "meow.png" meow.png downloading part 1 of u2net finished downloading part 1 of u2net downloading part 2 of u2net finished downloading part 2 of u2net downloading part 3 of u2net finished downloading part 3 of u2net downloading part 4 of u2net finished downloading part 4 of u2net Traceback (most recent call last): File "C:\Users\aboba\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\aboba\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\Programs\backgroundremover-main\backgroundremover\cmd\cli.py", line 253, in main() File "D:\Programs\backgroundremover-main\backgroundremover\cmd\cli.py", line 239, in main remove( File "D:\Programs\backgroundremover-main\backgroundremover\bg.py", line 179, in remove model = get_model(model_name) File "D:\Programs\backgroundremover-main\backgroundremover\bg.py", line 167, in get_model return detect.load_model(model_name="u2net") File "D:\Programs\backgroundremover-main\backgroundremover\u2net\detect.py", line 55, in load_model utilities.download_files_from_github( File "D:\Programs\backgroundremover-main\backgroundremover\utilities.py", line 347, in download_files_from_github os.remove(part.name) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\aboba\AppData\Local\Temp\tmpsbhw0_8x' PS D:\Programs\backgroundremover-main>

issaysa commented 1 year ago

You can add 1 line on backgroundremover/utilities.py line 347

    finally:
        for part in parts:
            part.close()
            os.remove(part.name)

like this.

343intact commented 1 year ago

You can add 1 line on backgroundremover/utilities.py line 347

    finally:
        for part in parts:
            part.close()
            os.remove(part.name)

like this.

I think it works, got another error now lol. Thank you

nadermx commented 1 year ago

I just pushed a version, testing on local, but if you all could try 0.2 here in a bit with this commit added, https://github.com/nadermx/backgroundremover/commit/52948ef8b9b416f8411acb103ef614c2fc08c258 to let me know if windows works I would greatly appreciate it

343intact commented 1 year ago

I just pushed a version, testing on local, but if you all could try 0.2 here in a bit with this commit added, 52948ef to let me know if windows works I would greatly appreciate it

I've just tested this on Windows 10, replied to you in another issue