From b29b9a678c68f0f03bc3f419bf5dfde5f175dc20 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Thu, 12 Oct 2023 17:10:06 +0200 Subject: [PATCH] Add warning about pip when binary is missing on linux --- wgpu/backends/rs_ffi.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/wgpu/backends/rs_ffi.py b/wgpu/backends/rs_ffi.py index 46733504..60507bba 100644 --- a/wgpu/backends/rs_ffi.py +++ b/wgpu/backends/rs_ffi.py @@ -84,8 +84,10 @@ def get_wgpu_lib_path(): # Note that this can be a false positive, e.g. ARM linux. embedded_path = get_resource_filename(lib_filename) if not os.path.isfile(embedded_path): # no-cover + download_hint = _maybe_get_hint_on_download_script() + pip_hint = _maybe_get_pip_hint() raise RuntimeError( - f"Could not find WGPU library in {embedded_path}. {_maybe_get_hint_on_download_script()}" + f"Could not find WGPU library in {embedded_path}. {download_hint} {pip_hint}" ) else: return embedded_path @@ -103,6 +105,29 @@ def _maybe_get_hint_on_download_script(): return "" +def _maybe_get_pip_hint(): + if not sys.platform.startswith("linux"): + return "" + + # Get pip version + pip_version = () + try: + import pip # noqa + + parts = [] + for x in pip.__version__.split("."): + if not x.isnumeric(): + break + parts.append(int(x)) + pip_version = tuple(parts) + except Exception: + pass + + if pip_version < (20, 3): + return "If you install wgpu with pip, pip needs to be at least version 20.3 or the wgpu-native binary may not be included." + return "" + + # Configure cffi and load the dynamic library # NOTE: `import wgpu.backends.rs` is used in pyinstaller tests to verify # that we can load the DLL after freezing