From a009e3048df14695e7c9cb6f794bbc8fe7930fb8 Mon Sep 17 00:00:00 2001 From: Arusekk Date: Mon, 3 Mar 2025 11:41:27 +0100 Subject: [PATCH] Fix Python 3.8 to 3.11 Previous logic required old setuptools on py3.8 up to py3.11. So if new setuptools was installed, importing unicorn always failed with ImportError on these Python versions. It now tries to use old setuptools on py3.8, but falls back gracefully to not using anything. So it works on py3.9+ fully, and on py3.8 it also works but with more limited path discovery (I think it is enough, since no one complained yet). Fixes: 0c34496a395eac567dc24eb6574550938a52b126 ("Modify canonicals import") Ref: https://github.com/unicorn-engine/unicorn/pull/2016/commits/0c34496a395eac567dc24eb6574550938a52b126 Ref: https://github.com/Gallopsled/pwntools/pull/2556 --- bindings/python/unicorn/unicorn_py3/unicorn.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bindings/python/unicorn/unicorn_py3/unicorn.py b/bindings/python/unicorn/unicorn_py3/unicorn.py index 8684a391e3..f7e09a77f1 100644 --- a/bindings/python/unicorn/unicorn_py3/unicorn.py +++ b/bindings/python/unicorn/unicorn_py3/unicorn.py @@ -114,14 +114,17 @@ def _load_lib(path: Path, lib_name: str): # - global load # - python's lib directory - if sys.version_info.minor >= 12: + if sys.version_info >= (3, 9): from importlib import resources canonicals = resources.files('unicorn') / 'lib' else: - import pkg_resources + try: + import pkg_resources - canonicals = pkg_resources.resource_filename('unicorn', 'lib') + canonicals = pkg_resources.resource_filename('unicorn', 'lib') + except ImportError: + canonicals = None lib_locations = [ os.getenv('LIBUNICORN_PATH'),