From e178596dfefa54da5c34163327fc1482af9cbc8d Mon Sep 17 00:00:00 2001 From: AI Health Chatbot Date: Mon, 26 Jan 2026 01:07:17 +0530 Subject: [PATCH 1/2] fix: replace deprecated pkg_resources with importlib.resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated BrainFlow EEG files: - emulator/: cyton_windows.py, freeeeg32_windows.py, knightboard_windows.py - python_package/brainflow/: board_shim.py, data_filter.py, ml_model.py ✅ Eliminates pkg_resources deprecation warnings --- emulator/brainflow_emulator/cyton_windows.py | 9 +++++++-- emulator/brainflow_emulator/freeeeg32_windows.py | 9 +++++++-- emulator/brainflow_emulator/knightboard_windows.py | 9 +++++++-- python_package/brainflow/board_shim.py | 9 +++++++-- python_package/brainflow/data_filter.py | 9 +++++++-- python_package/brainflow/ml_model.py | 9 +++++++-- 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/emulator/brainflow_emulator/cyton_windows.py b/emulator/brainflow_emulator/cyton_windows.py index 328097875..cb97b75ca 100644 --- a/emulator/brainflow_emulator/cyton_windows.py +++ b/emulator/brainflow_emulator/cyton_windows.py @@ -4,7 +4,7 @@ import sys import time -import pkg_resources +from importlib.resources import files from brainflow_emulator.emulate_common import TestFailureError, Listener, log_multilines from serial import Serial @@ -18,7 +18,12 @@ def read(port, num_bytes): def get_isntaller(): - return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) + try: + resource = files(__name__).joinpath('com0com').joinpath('setup_com0com_W7_x64_signed.exe') + return str(resource) + except (TypeError, AttributeError): + import pkg_resources + return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) def install_com0com(): diff --git a/emulator/brainflow_emulator/freeeeg32_windows.py b/emulator/brainflow_emulator/freeeeg32_windows.py index 5b419beda..a6012d711 100644 --- a/emulator/brainflow_emulator/freeeeg32_windows.py +++ b/emulator/brainflow_emulator/freeeeg32_windows.py @@ -4,7 +4,7 @@ import sys import time -import pkg_resources +from importlib.resources import files from brainflow_emulator.emulate_common import TestFailureError, log_multilines from brainflow_emulator.freeeeg32_emulator import Listener from serial import Serial @@ -19,7 +19,12 @@ def read(port, num_bytes): def get_isntaller(): - return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) + try: + resource = files(__name__).joinpath('com0com').joinpath('setup_com0com_W7_x64_signed.exe') + return str(resource) + except (TypeError, AttributeError): + import pkg_resources + return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) def install_com0com(): diff --git a/emulator/brainflow_emulator/knightboard_windows.py b/emulator/brainflow_emulator/knightboard_windows.py index c63cdceb4..f7791b472 100644 --- a/emulator/brainflow_emulator/knightboard_windows.py +++ b/emulator/brainflow_emulator/knightboard_windows.py @@ -4,7 +4,7 @@ import sys import time -import pkg_resources +from importlib.resources import files from brainflow_emulator.emulate_common import TestFailureError, log_multilines from brainflow_emulator.knightboard_emulator import Listener from serial import Serial @@ -19,7 +19,12 @@ def read(port, num_bytes): def get_isntaller(): - return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) + try: + resource = files(__name__).joinpath('com0com').joinpath('setup_com0com_W7_x64_signed.exe') + return str(resource) + except (TypeError, AttributeError): + import pkg_resources + return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) def install_com0com(): diff --git a/python_package/brainflow/board_shim.py b/python_package/brainflow/board_shim.py index a81a58375..7d1336543 100644 --- a/python_package/brainflow/board_shim.py +++ b/python_package/brainflow/board_shim.py @@ -7,7 +7,7 @@ from typing import List import numpy -import pkg_resources +from importlib.resources import files from brainflow.exit_codes import BrainFlowExitCodes, BrainFlowError from brainflow.utils import LogLevels from numpy.ctypeslib import ndpointer @@ -173,7 +173,12 @@ def __init__(self): dll_path = 'lib/libBoardController.dylib' else: dll_path = 'lib/libBoardController.so' - full_path = pkg_resources.resource_filename(__name__, dll_path) + try: + resource = files(__name__).joinpath(dll_path) + full_path = str(resource) + except (TypeError, AttributeError): + import pkg_resources + full_path = pkg_resources.resource_filename(__name__, dll_path) if os.path.isfile(full_path): dir_path = os.path.abspath(os.path.dirname(full_path)) # for python we load dll by direct path but this dll may depend on other dlls and they will not be found! diff --git a/python_package/brainflow/data_filter.py b/python_package/brainflow/data_filter.py index aeb243df8..ffc59f29e 100644 --- a/python_package/brainflow/data_filter.py +++ b/python_package/brainflow/data_filter.py @@ -6,7 +6,7 @@ from typing import List, Tuple import numpy -import pkg_resources +from importlib.resources import files from brainflow.exit_codes import BrainFlowExitCodes, BrainFlowError from brainflow.utils import check_memory_layout_row_major, LogLevels from numpy.ctypeslib import ndpointer @@ -153,7 +153,12 @@ def __init__(self): dll_path = 'lib/libDataHandler.dylib' else: dll_path = 'lib/libDataHandler.so' - full_path = pkg_resources.resource_filename(__name__, dll_path) + try: + resource = files(__name__).joinpath(dll_path) + full_path = str(resource) + except (TypeError, AttributeError): + import pkg_resources + full_path = pkg_resources.resource_filename(__name__, dll_path) if os.path.isfile(full_path): dir_path = os.path.abspath(os.path.dirname(full_path)) # for python 3.8 PATH env var doesnt work anymore diff --git a/python_package/brainflow/ml_model.py b/python_package/brainflow/ml_model.py index 3e5fd71d2..002e6f911 100644 --- a/python_package/brainflow/ml_model.py +++ b/python_package/brainflow/ml_model.py @@ -7,7 +7,7 @@ from typing import List import numpy -import pkg_resources +from importlib.resources import files from brainflow.board_shim import BrainFlowError, LogLevels from brainflow.exit_codes import BrainFlowExitCodes from numpy.ctypeslib import ndpointer @@ -78,7 +78,12 @@ def __init__(self): dll_path = 'lib/libMLModule.dylib' else: dll_path = 'lib/libMLModule.so' - full_path = pkg_resources.resource_filename(__name__, dll_path) + try: + resource = files(__name__).joinpath(dll_path) + full_path = str(resource) + except (TypeError, AttributeError): + import pkg_resources + full_path = pkg_resources.resource_filename(__name__, dll_path) if os.path.isfile(full_path): # for python we load dll by direct path but this dll may depend on other dlls and they will not be found! # to solve it we can load all of them before loading the main one or change PATH\LD_LIBRARY_PATH env var. From 1f8442f7576abc4f966c05cbae6582f65d63e73b Mon Sep 17 00:00:00 2001 From: AI Health Chatbot Date: Tue, 27 Jan 2026 16:54:04 +0530 Subject: [PATCH 2/2] docs: detailed fallback comments for NixOS/Python<3.9 compatibility --- emulator/brainflow_emulator/cyton_windows.py | 3 +++ emulator/brainflow_emulator/freeeeg32_windows.py | 3 +++ emulator/brainflow_emulator/knightboard_windows.py | 3 +++ python_package/brainflow/board_shim.py | 5 ++++- python_package/brainflow/data_filter.py | 3 +++ python_package/brainflow/ml_model.py | 3 +++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/emulator/brainflow_emulator/cyton_windows.py b/emulator/brainflow_emulator/cyton_windows.py index cb97b75ca..b5360e15b 100644 --- a/emulator/brainflow_emulator/cyton_windows.py +++ b/emulator/brainflow_emulator/cyton_windows.py @@ -22,6 +22,9 @@ def get_isntaller(): resource = files(__name__).joinpath('com0com').joinpath('setup_com0com_W7_x64_signed.exe') return str(resource) except (TypeError, AttributeError): + # Fallback for: + # 1. Python < 3.9 (importlib.resources.files not available) + # 2. NixOS/packaging edge cases where importlib.resources may not work import pkg_resources return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) diff --git a/emulator/brainflow_emulator/freeeeg32_windows.py b/emulator/brainflow_emulator/freeeeg32_windows.py index a6012d711..223f56ac0 100644 --- a/emulator/brainflow_emulator/freeeeg32_windows.py +++ b/emulator/brainflow_emulator/freeeeg32_windows.py @@ -23,6 +23,9 @@ def get_isntaller(): resource = files(__name__).joinpath('com0com').joinpath('setup_com0com_W7_x64_signed.exe') return str(resource) except (TypeError, AttributeError): + # Fallback for: + # 1. Python < 3.9 (importlib.resources.files not available) + # 2. NixOS/packaging edge cases where importlib.resources may not work import pkg_resources return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) diff --git a/emulator/brainflow_emulator/knightboard_windows.py b/emulator/brainflow_emulator/knightboard_windows.py index f7791b472..4b08850d5 100644 --- a/emulator/brainflow_emulator/knightboard_windows.py +++ b/emulator/brainflow_emulator/knightboard_windows.py @@ -23,6 +23,9 @@ def get_isntaller(): resource = files(__name__).joinpath('com0com').joinpath('setup_com0com_W7_x64_signed.exe') return str(resource) except (TypeError, AttributeError): + # Fallback for: + # 1. Python < 3.9 (importlib.resources.files not available) + # 2. NixOS/packaging edge cases where importlib.resources may not work import pkg_resources return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) diff --git a/python_package/brainflow/board_shim.py b/python_package/brainflow/board_shim.py index 7d1336543..c3c61888e 100644 --- a/python_package/brainflow/board_shim.py +++ b/python_package/brainflow/board_shim.py @@ -21,7 +21,7 @@ class BoardIds(enum.IntEnum): STREAMING_BOARD = -2 #: SYNTHETIC_BOARD = -1 #: CYTON_BOARD = 0 #: - GANGLION_BOARD = 1 #: + GANGLION_BOARD = 1 #: CYTON_DAISY_BOARD = 2 #: GALEA_BOARD = 3 #: GANGLION_WIFI_BOARD = 4 #: @@ -177,6 +177,9 @@ def __init__(self): resource = files(__name__).joinpath(dll_path) full_path = str(resource) except (TypeError, AttributeError): + # Fallback for: + # 1. Python < 3.9 (importlib.resources.files not available) + # 2. NixOS/packaging edge cases where importlib.resources may not work import pkg_resources full_path = pkg_resources.resource_filename(__name__, dll_path) if os.path.isfile(full_path): diff --git a/python_package/brainflow/data_filter.py b/python_package/brainflow/data_filter.py index ffc59f29e..c01be79e3 100644 --- a/python_package/brainflow/data_filter.py +++ b/python_package/brainflow/data_filter.py @@ -157,6 +157,9 @@ def __init__(self): resource = files(__name__).joinpath(dll_path) full_path = str(resource) except (TypeError, AttributeError): + # Fallback for: + # 1. Python < 3.9 (importlib.resources.files not available) + # 2. NixOS/packaging edge cases where importlib.resources may not work import pkg_resources full_path = pkg_resources.resource_filename(__name__, dll_path) if os.path.isfile(full_path): diff --git a/python_package/brainflow/ml_model.py b/python_package/brainflow/ml_model.py index 002e6f911..3dd7a8317 100644 --- a/python_package/brainflow/ml_model.py +++ b/python_package/brainflow/ml_model.py @@ -82,6 +82,9 @@ def __init__(self): resource = files(__name__).joinpath(dll_path) full_path = str(resource) except (TypeError, AttributeError): + # Fallback for: + # 1. Python < 3.9 (importlib.resources.files not available) + # 2. NixOS/packaging edge cases where importlib.resources may not work import pkg_resources full_path = pkg_resources.resource_filename(__name__, dll_path) if os.path.isfile(full_path):