Rembg is a tool to remove images background
better error msgs
Daniel Gatis6db7b4abef6f
diff --git a/README.md b/README.mdindex 2a07dd6..9236bfa 100644--- a/README.md+++ b/README.md@@ -41,23 +41,16 @@ python: >=3.11, <3.14## Installation-If you have `onnxruntime` already installed, just install `rembg`:+Choose **one** of the following backends based on your hardware:-```bash-pip install rembg # for library-pip install "rembg[cli]" # for library + cli-```--Otherwise, install `rembg` with explicit CPU/GPU support.--### CPU support:+### CPU support```bash-pip install rembg[cpu] # for library+pip install "rembg[cpu]" # for librarypip install "rembg[cpu,cli]" # for library + cli```-### GPU support (NVidia/Cuda):+### GPU support (NVIDIA/CUDA)First of all, you need to check if your system supports the `onnxruntime-gpu`.diff --git a/rembg/bg.py b/rembg/bg.pyindex c8c752e..d878287 100644--- a/rembg/bg.py+++ b/rembg/bg.py@@ -4,7 +4,21 @@ from enum import Enumfrom typing import Any, List, Optional, Tuple, Union, castimport numpy as np-import onnxruntime as ort++try:+ import onnxruntime as ort # type: ignore[import-untyped]+except ImportError:+ print("No onnxruntime backend found.")+ print("Please install rembg with CPU or GPU support:")+ print()+ print(' pip install "rembg[cpu]" # for CPU')+ print(' pip install "rembg[gpu]" # for NVIDIA/CUDA GPU')+ print()+ print(+ "For more information, see: https://github.com/danielgatis/rembg#installation"+ )+ sys.exit(1)+from PIL import Image, ImageOpsfrom PIL.Image import Image as PILImagefrom pymatting.alpha.estimate_alpha_cf import estimate_alpha_cfdiff --git a/rembg/cli.py b/rembg/cli.pyindex 8625ab5..dc1e747 100644--- a/rembg/cli.py+++ b/rembg/cli.py@@ -1,4 +1,25 @@-import click+import sys++# Fast path for --version (avoid importing heavy dependencies)+if len(sys.argv) == 2 and sys.argv[1] in ("--version", "-V"):+ from importlib.metadata import version++ print(f"rembg, version {version('rembg')}")+ sys.exit(0)++try:+ import click+except ImportError:+ print("The CLI dependencies are not installed.")+ print("Please install rembg with CLI support:")+ print()+ print(' pip install "rembg[cpu,cli]" # for CPU')+ print(' pip install "rembg[gpu,cli]" # for NVIDIA/CUDA GPU')+ print()+ print(+ "For more information, see: https://github.com/danielgatis/rembg#installation"+ )+ sys.exit(1)from . import __version__from .commands import command_functions