diff options
author | Josh Blum <josh@joshknows.com> | 2021-01-22 21:09:56 -0600 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2021-01-27 07:31:08 -0800 |
commit | 5e8286eeaee858543b04043c5642550e466bf8ec (patch) | |
tree | 7db0d1cfccc764dde3e2991621dd1a8def6744d7 /gnuradio-runtime/python | |
parent | b3f2edadb719c7d639fb48e48368121ec6eee911 (diff) |
python: add the dll runtime path in __init__.py
python3.8 and up need to have the dll search path set explicitly before importing.
More details can be found here: https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
Without the fix, python libraries will fail to import regardless of how PATH is configured.
The solution searches for the runtime path for gnuradio dlls and calls add_dll_directory() before imports.
As a precedent, a similar behaviour is implemented in the gi/__init__.py module used with pygtk.
Signed-off-by: Josh Blum <josh@joshknows.com>
Diffstat (limited to 'gnuradio-runtime/python')
-rw-r--r-- | gnuradio-runtime/python/gnuradio/__init__.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gnuradio-runtime/python/gnuradio/__init__.py b/gnuradio-runtime/python/gnuradio/__init__.py index ab3bbdbf19..db7bc5cc48 100644 --- a/gnuradio-runtime/python/gnuradio/__init__.py +++ b/gnuradio-runtime/python/gnuradio/__init__.py @@ -13,6 +13,19 @@ GNU Radio is licensed under the GNU General Public License (GPL) version 3. All import os +# python3.8 and up need to have the dll search path set +# https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew +if os.name == 'nt' and hasattr(os, 'add_dll_directory'): + root_dir = __file__ + for i in range(5): #limit search depth + root_dir = os.path.dirname(root_dir) + bin_dir = os.path.join(root_dir, 'bin') + if os.path.exists(bin_dir): + try: os.add_dll_directory(bin_dir) + except Exception as ex: + print('add_dll_directory(%s): %s'%(bin_dir, ex)) + break + # Check if the gnuradio package is installed or whether we're attempting to import it from # the build directory. path_ending = os.path.join('gnuradio-runtime', 'python', 'gnuradio', '__init__.py') |