Post Go back to editing

libm2k with python bindings installation for mac os -- issues with libiio

Hi,

I have been struggling to get libm2k installed in python on my Mac computer. 

I get the following error when importing libm2k in python:

Python 3.10.8 (main, Nov  1 2022, 12:24:20) [Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import libm2k
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/peterkinget/Python/venv-iMac-basement/lib/python3.10/site-packages/libm2k.py", line 15, in <module>
    import _libm2k
ImportError: dlopen(/Users/peterkinget/Python/venv-iMac-basement/lib/python3.10/site-packages/_libm2k.cpython-310-darwin.so, 0x0002): Library not loaded: '@rpath/iio.framework/Versions/0.24/iio'
  Referenced from: '/Users/peterkinget/Python/venv-iMac-basement/lib/python3.10/site-packages/_libm2k.cpython-310-darwin.so'
  Reason: tried: '/usr/local/lib/iio.framework/Versions/0.24/iio' (no such file), '/usr/local/lib/iio.framework/Versions/0.24/iio' (no such file), '/Library/Frameworks/iio.framework/Versions/0.24/iio' (no such file), '/System/Library/Frameworks/iio.framework/Versions/0.24/iio' (no such file)
>>> 

I followed the install process that I could find online starting at https://wiki.analog.com/university/tools/m2k/libm2k/libm2k

  • Download the libiio-darwin.pkg for your system (from the nightly builds) and install it by running sudo installer -pkg /path/to/package.pkg -target /. ⇒ did that (first by clicking the package and doing the install through the GUI and then later through the command line `sudo installer` -- not sure if that would make a difference. Did both methods for all packages installed. 
  • Download the libm2k-darwin.pkg for your system and install it by running sudo installer -pkg /path/to/package.pkg -target /. ⇒ did that
    now, that package also included a libiio and I installed that as well. It is not clear how libiio should be installed correctly ...
  • The m2kcli command line tool is also installed with the package.
    • ⇒ got that to work after installing libserial with `brew install libserial`

Created a virtual environment starting from python3.10

However, I get the error pasted above when trying to import libm2k. 

I did try to download the wheels directly from the libm2k python bindings GitHub but none of the wheels seemed to be compatible with my system/python version.

I am working on an iMAC with Monterey

I am familiar with linux, command line, ... willing to move some files manually in the right folders, but I cannot figure out where _libm2k.cpython-310-darwin.so wants the libiio files and how. 

Thanks, 

-- Peter Kinget

  • So I got this to work ... tl;dr: Use python 3.11

    on mac os from a terminal in the folder where the packages are downloaded I did the following:

    > sudo installer -pkg ./libiio-0.25.g29107ada.pkg -target /
    > sudo installer -pkg ../macOS-11_latest_main_libiio.pkg -target /
    > sudo installer -pkg ./libm2k-0.8.0.g5b961eb.pkg -target /

    Then tried:
    > /Library/Frameworks/libm2k.framework/Tools/m2kcli
    ⇒ did not work

    Did again:

    > sudo installer -pkg ./libiio-0.25.g29107ada.pkg -target /
    > /Library/Frameworks/libm2k.framework/Tools/m2kcli
    ⇒ worked!

    Installed python3.11 (using brew install python@3.11 )

    In virtual environment for python 3.11:
    > pip install -i https://test.pypi.org/simple/ libm2k --force-reinstall

    Then things worked in python as well ... 

  • Hi,

    The issue here is that the wiki docs for libm2k you mentioned above are outdated. We will make sure to add the necessary changes there.
    At the moment there is a major change done in libiio, which is the direct dependency for libm2k.
    Libiio main branch (which you mentioned here: > sudo installer -pkg ../macOS-11_latest_main_libiio.pkg -target / ) points to the new version of libiio - v1.0. This is incompatible with libiio v0.25 and libm2k v0.8.0. Seeing how the documentation points to the latest nightly builds of libiio it is expected to get errors when trying to run libm2k.
    We will update the documentation accordingly in order to point users to libiio v0.25 instead of the latest development build.

    Doing just the following steps (based on what you described above) should suffice:

    > sudo installer -pkg ./libiio-0.25.g29107ada.pkg -target /
    > sudo installer -pkg ./libm2k-0.8.0.g5b961eb.pkg -target /

    Thank you!
    -Alexandra