Wednesday, November 27, 2013

Installing gr-air-modes on Mac

Don't really have much time to write this up, but installing gr-air-modes is a bit tricky and took me a few hours. To the best of my recollection:


  • Use Macports to install gnuradio
  • Download the source from https://github.com/bistromath/gr-air-modes
  • During the make it complains about not being able to find the pmt libraries
I fixed this by adding the following lines to cmake/Modules/FindGnuradioRuntime.cmake after the other find_library command


  FIND_LIBRARY(
    GNURADIO_PMT_LIBRARIES
    NAMES gnuradio-pmt
    HINTS $ENV{GNURADIO_RUNTIME_DIR}/lib
          ${PC_GNURADIO_RUNTIME_LIBDIR}
          ${CMAKE_INSTALL_PREFIX}/lib/
          ${CMAKE_INSTALL_PREFIX}/lib64/
    PATHS /usr/local/lib
          /usr/local/lib64
          /usr/lib
          /usr/lib64

    )

and then adding GNURADIO_PMT_LIBRARIES to the MARK_AS_ADVANCED list

Then add ${GNURADIO_PMT_LIBRARIES} to target_link_libraries in lib/CMakeLists.txt


  • Compiling and installing now works, but we get a "Fatal Python error: PyThreadState_Get: no current thread" when running modes_rx


Change the cmake command to

cmake -DPYTHON_LIBRARY=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib ../


Now it should work.

10 comments:

  1. Chris:
    Thanks for posting this. Yet, it didn't work for me. I get complains about not finding gnuradio-core and gruel:

    pcostaMBP:build pc$ cmake ../
    -- The CXX compiler identification is Clang 5.0.0
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Build type not specified: defaulting to release.
    -- Boost version: 1.55.0
    -- Found the following Boost libraries:
    -- date_time
    -- program_options
    -- filesystem
    -- system
    -- thread
    -- Found PkgConfig: /opt/local/bin/pkg-config (found version "0.28")
    -- checking for module 'gnuradio-core'
    -- package 'gnuradio-core' not found
    -- Could NOT find GRUEL (missing: GRUEL_LIBRARIES GRUEL_INCLUDE_DIRS)
    -- checking for module 'gnuradio-core'
    -- package 'gnuradio-core' not found
    -- Could NOT find GNURADIO_CORE (missing: GNURADIO_CORE_LIBRARIES GNURADIO_CORE_INCLUDE_DIRS)
    CMake Error at CMakeLists.txt:76 (message):
    Gruel required to compile gr-air-modes

    I then tried your hint above *and* changing from /usr/local... to /opt/local/...
    since this is where macports installs gnuradio.

    ReplyDelete
    Replies
    1. ...continuing (clicked the wrong button)
      The above also did not work and I basically got the very same message (i.e. not finding gnuradio-core and gruel).
      Do you have any idea of what might be happening?
      Thanks very much for any hint you can give me on this.
      Best regards,
      Paulo

      Delete
    2. Hi Paulo,

      Are you using the latest version of hr-air-modes from the Github repository? The relevant portion of my cake output:

      -- The CXX compiler identification is Clang 5.0.0
      -- The C compiler identification is Clang 5.0.0
      -- Check for working CXX compiler: /usr/bin/c++
      -- Check for working CXX compiler: /usr/bin/c++ -- works
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working C compiler: /usr/bin/cc
      -- Check for working C compiler: /usr/bin/cc -- works
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Build type not specified: defaulting to release.
      -- Boost version: 1.55.0
      -- Found the following Boost libraries:
      -- date_time
      -- program_options
      -- filesystem
      -- system
      -- thread
      -- Found PythonLibs: /usr/lib/libpython2.7.dylib (found suitable version "2.7.5", minimum required is "2")
      -- Found PkgConfig: /opt/local/bin/pkg-config (found version "0.28")
      Checking for GNU Radio Module: RUNTIME
      -- checking for module 'gnuradio-runtime'
      -- found gnuradio-runtime, version 3.7.2.1
      * INCLUDES=/opt/local/include
      * LIBS=/opt/local/lib/libgnuradio-runtime.dylib;/opt/local/lib/libgnuradio-pmt.dylib
      -- Found GNURADIO_RUNTIME: /opt/local/lib/libgnuradio-runtime.dylib;/opt/local/lib/libgnuradio-pmt.dylib
      GNURADIO_RUNTIME_FOUND = TRUE

      There's a few interesting differences like yours not requiring PythonLibs version 2 and looking for gnuradio-core rather than gnuradio-runtime that makes me think you may be using an older version.

      Delete
  2. Chris,

    Thanks very much. You were right, I was with an older version. I downloaded the correct one and run cmake with the modifications you mentioned.
    Unfortunately, it stalled at:


    --
    -- Python checking for PyZMQ
    -- Python checking for PyZMQ - not found
    CMake Error at CMakeLists.txt:87 (message):
    Python ZMQ bindings not found.


    -- Configuring incomplete, errors occurred!
    See also "/Users/pc/downloads/gr-air-modes-master/build/CMakeFiles/CMakeOutput.log".
    pcostaMBP:build pc$

    But this was something else. I did install Py27-zmq via macports but I'm still getting the same error, after sending a few hours browsing the web.
    Anyways, your hint worked nicely. Thanks again for sharing it.

    Best regards,
    Paulo

    ReplyDelete
  3. I would check to make sure the active version of python is the macports version rather than the Apple version:

    $ port select python
    Warning: port definitions are more than two weeks old, consider updating them by running 'port selfupdate'.
    Available versions for python:
    none
    python25-apple
    python26-apple
    python27 (active)
    python27-apple

    You can also check to see if Python sees the zmq library:
    $ python
    Python 2.7.6 (default, Nov 19 2013, 19:15:05)
    [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import zmq
    >>>

    If you get an error, the library isn't successfully installed for that version of python:

    >>> import nothing
    Traceback (most recent call last):
    File "", line 1, in
    ImportError: No module named nothing
    >>>

    ReplyDelete
  4. Chris,
    Once again, thanks for your help. You went right to the nail, port select pointed to "none" so I fixed it and also ensured that the right python (macports 2.7) would be called (with the alias command). After testing all settings I proceed and was able to install.
    Since life isn't that easy, running modes_rx doesn't do the trick:

    pcostaMBP:build pc$ modes_rx
    Traceback (most recent call last):
    File "/usr/local/bin/modes_rx", line 28, in
    import air_modes
    ImportError: No module named air_modes

    I rebooted, ran selfupdate, upgrade, reinstalled, all to no avail. Simply put, the installation goes well and modes_rx is there at /usr/local/bin. Yet, I kept getting the above. Python gives me the same output:

    pcostaMBP:build pc$ python
    Python 2.7.6 (default, Nov 18 2013, 15:12:51)
    [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import zmq
    >>> import numpy
    >>> import scipy
    >>> import osmosdr
    Mac OS; Clang version 5.0 (clang-500.2.79); Boost_105500; UHD_003.006.002-0-unknown

    >>> import pyqt4
    Traceback (most recent call last):
    File "", line 1, in
    ImportError: No module named pyqt4
    >>> import air_modes
    Traceback (most recent call last):
    File "", line 1, in
    ImportError: No module named air_modes
    >>> ^D
    pcostaMBP:build pc$

    I don't think pyqt4 (which is listed in macports installed) is the main culprit. It might be that I just have a broken system and will have to start from scratch to fix it (i.e. installing Mavericks from zero, then use either homebrew or macports, not both as I have now in my system).
    In any case, I'm grateful for your help. The tip above works as a charm. I'll just try it in another machine before "zeroing" my computer.



    ReplyDelete
    Replies
    1. At least we're making progress. It looks like some things didn't make it into your python path properly. You can check where it's trying to load modules from within python:

      $ python
      Python 2.7.6 (default, Nov 19 2013, 19:15:05)
      [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import sys
      >>> print sys.path
      ['', '/Library/Frameworks/SQLite3.framework/Versions/3/Python/2.7', '/Library/Frameworks/GDAL.framework/Versions/1.9/Python/2.7/site-packages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gtk-2.0', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-2.9.5-osx_cocoa', '/Library/Python/2.7/site-packages']

      At least in my install, air_modes is at /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/air_modes

      Either your python path is wrong (in which case you may want to think about uninstalling/reinstalling python in macports) or your air_modes is in the wrong location (which can be fixed by passing additional arguments to cmake).

      If I had to guess, I would say it's your python path since it can't find pyqt4 either. It's easy enough in macports to force a reinstall of python, so I'd try that before wiping the drive.

      Delete
  5. Chris,
    I uninstalled:
    - Macports and all its ports
    - Homebrew
    - Fink
    Then, reboot, fixed preferences, and various maintenance tasks.
    I proceed installing macports, selfupdating, and the first port was py27-pyqt4, which installed python 2.7, PyQt4 and all their dependencies. I tested it and all seemed correct. This includes the commands:
    - import pyqt4
    - import zmq
    - import numpy
    - import scipy
    Yet, when running the cmake statement I still get the same result. That is, all go well, except for this line:
    -- pyuic4 not found, not installing GUI application
    sudo make and sudo make install run nicely, but modes_rx doesn't work and python cannot see air_modes.
    I did run the sys.path and the location of air_modes is the same as yours and it is included in the path.
    The only thing that looked weird to me was this line in the cmake output:
    -- Found PythonLibs: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib (found version "2.7.5")
    which is inconsistent with this other line in the same output:
    -- Found PythonInterp: /opt/local/bin/python (found version "2.7.6")

    That is, in one line the parser found the macports python (2.7.6) and in a subsequent line it found the apple python (2.7.5).
    I tried reinstalling many times and with different configurations of PYTHONPATH in my .profile (including none), but always got the same result from cmake.
    Apart from:
    1) port select -set python python2.7
    2) alias python="/opt/local/bin/python2.7
    3) export PYTHONPATH="/opt.../site-packages"
    is there any place in which I can enforce the use of the macports python?
    More specifically, that line in cmake is looking at the apple python while every other line looks at the macports python.
    Thanks again for you patience on this.


    ReplyDelete
  6. Same problem here. gr_air_modes built without errors (without the gui, as I don't have uic4 installed). But when running, it doesn't find air_modes.py

    Traceback (most recent call last):
    File "/usr/local/bin/modes_rx", line 28, in
    import air_modes
    ImportError: No module named air_modes

    Looking at what got installed, it installed air_modes_swig.py, but nothing called air_modes.py:

    -rwxr-xr-x 1 root wheel 306956 Apr 27 15:28 _air_modes_swig.so
    -rw-r--r-- 1 root wheel 28692 Apr 27 15:28 air_modes_swig.py
    -rw-r--r-- 1 root wheel 45607 Apr 27 15:28 air_modes_swig.pyc
    -rw-r--r-- 1 root wheel 45607 Apr 27 15:28 air_modes_swig.pyo

    Gnuradio 3.7.2.1. MacOS 10.8.5.

    ReplyDelete
  7. Hi

    Firstly thankyou for all of the above advice, I feel I'm nearly there. All dependencies installed via macports. Code built from https://github.com/bistromath/gr-air-modes. But the command

    sudo ldconfig

    is not available on Mac 10.9.5. When I execute the modes_rx command I get the following:
    sudo /usr/local/bin/modes_gui
    Traceback (most recent call last):
    File "/usr/local/bin/modes_gui", line 30, in
    import air_modes
    ImportError: No module named air_modes

    Any help greatly appreciated.

    ReplyDelete