This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

pc-ble-driver-py on Mac: ImportError: Image not found

Hi,

Getting this error using the latest version of pc-ble-driver-py on Mac with the latest version of Catalina for the example application heart_rate_collector from the examples folder:

Traceback (most recent call last):
  File "./heart_rate_collector.py", line 208, in <module>
    init(sys.argv[1])
  File "./heart_rate_collector.py", line 56, in init
    from pc_ble_driver_py.ble_driver import (
  File "/Users/espen/.virtualenvs/hypersension-isenseu-console/lib/python3.8/site-packages/pc_ble_driver_py/ble_driver.py", line 77, in <module>
    import pc_ble_driver_py.lib.nrf_ble_driver_sd_api_v5 as driver
  File "/Users/espen/.virtualenvs/hypersension-isenseu-console/lib/python3.8/site-packages/pc_ble_driver_py/lib/nrf_ble_driver_sd_api_v5.py", line 13, in <module>
    from . import _nrf_ble_driver_sd_api_v5
ImportError: dlopen(/Users/espen/.virtualenvs/hypersension-isenseu-console/lib/python3.8/site-packages/pc_ble_driver_py/lib/_nrf_ble_driver_sd_api_v5.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.8/Python
  Referenced from: /Users/espen/.virtualenvs/hypersension-isenseu-console/lib/python3.8/site-packages/pc_ble_driver_py/lib/_nrf_ble_driver_sd_api_v5.so
  Reason: image not found

I've tried every combination possible of python installations, from using brew, standard installation from python.org, Anaconda to using pyenv. I've also tested using an isolated environment using pyenv and virtualenvwrapper, which is supposed to create a completely isolated python environment including plugins/packages. 

As you can see from the error message, _nrf_ble_driver_sd_api_v5.so is trying to access a library in /Library/Frameworks/Python.framework/Versions/3.8/Python. This folder does not exist, and looking at my environment settings, to paths are pointing to this directory either. 

Any help on this is much appreciated!

  • Hello,

    I tried this now on Catalina with python v3.8.6 installed from python.org, but I did not run into this problem. When you tested the different installations, did you make sure invoke the correct interpreter since you have mulitple installations (ie one distributed with macos, from brew, and python.org)?

    The python3 executable from python.org got installed to /usr/local/bin/python3 in my case. So I used the following command when installing the package from PyPi (could have used pyenv too):  

    $ /usr/local/bin/python3 -m pip install --user  pc-ble-driver-py

    And this command to run the example script afterwards:

    $ /usr/local/bin/python3 hear_rate_collector.py NRF52 /dev/tty.usbmodemxxx

  • Thank you for the quick response. This was actually very clarifying! 

    The latest version from Python.org is 3.9, which caused a different error, described in this support ticket: pc-ble-driver-py on Mac: "ImportError: dynamic..

    I downgraded the official version of Python (from python.org) to 3.8.6, which installs in /Library/Frameworks/Python.framework/Versions/3.8 and that did the trick :-) 

    Based on this I suspect that something in the library file is hardcoded to the standard python install path (/Library/Frameworks/Python.framework/Versions/XXX). 

    But anyway, your description using the official Python version 3.8.6 works. Problem solved :) 

  • Thanks for reporting back and for explaining the actual problem! I will report this internally.

  • You guys hardcoded your library to look for python in a location where it's no longer installed, as of Monterey.

    ImportError: dlopen(.../lib/python3.9/site-packages/pc_ble_driver_py/lib/_nrf_ble_driver_sd_api_v5.so, 0x0002): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.9/Python
      Referenced from: .../lib/python3.9/site-packages/pc_ble_driver_py/lib/_nrf_ble_driver_sd_api_v5.so
      Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.9/Python' (no such file), '/System/Library/Frameworks/Python.framework/Versions/3.9/Python' (no such file)
    

    I can work around the issue by creating a symlink

    ln -s /usr/local/Cellar/[email protected]/3.9.7/Frameworks/Python.framework/Versions/3.9/ /Library/Frameworks/Python.framework/Versions/3.9
    

    but I shouldn't have to. This should be fixed to work with python installs in the new location.

Related