From f2b3aefd54b5bcd9d09d2a1e01630ac3bd30d2a0 Mon Sep 17 00:00:00 2001 From: citb0in <119492930+citb0in@users.noreply.github.com> Date: Fri, 6 Jan 2023 14:00:59 +0100 Subject: [PATCH] Fix to allow import/use module from any folder Load the shared library "ice_secp256k1.dll" or "ice_secp256k1.so" located in the same directory as the python module. By this fix the user can import the module from *ANY* directory using Python's CLI or IDE. Without this fix, the user can only import the module if the current working directory is the directory of this module. --- secp256k1.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/secp256k1.py b/secp256k1.py index 15f62b1..783d9c2 100644 --- a/secp256k1.py +++ b/secp256k1.py @@ -16,7 +16,8 @@ Zero=b'\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' #============================================================================== if platform.system().lower().startswith('win'): - dllfile = 'ice_secp256k1.dll' + dir_path = os.path.dirname(os.path.realpath(__file__)) + dllfile = dir_path + '/ice_secp256k1.dll' if os.path.isfile(dllfile) == True: pathdll = os.path.realpath(dllfile) ice = ctypes.CDLL(pathdll) @@ -24,7 +25,8 @@ print('File {} not found'.format(dllfile)) elif platform.system().lower().startswith('lin'): - dllfile = 'ice_secp256k1.so' + dir_path = os.path.dirname(os.path.realpath(__file__)) + dllfile = dir_path + '/ice_secp256k1.so' if os.path.isfile(dllfile) == True: pathdll = os.path.realpath(dllfile) ice = ctypes.CDLL(pathdll)