Configuring the Python UHD module for Mac - benjamin-havens/AMT_SQUAD GitHub Wiki
Note:
This is a fairly ad hoc guide. Some steps may not be necessary. Others may not be well-described. There are likely more efficient ways to do what we did. Use with discretion.
Preliminary steps
Install Python We used python 3.9.
(Optional) Install Homebrew This is a package manager for MacOS. It is useful for installing the needed dependencies. MacPorts is also an option.
Installation
Follow these tutorials: Python API tutorial and Ettus installation manual
These are helpful guides. Some adjustment will be needed; in particular, using a different package manager as apt-get is not supported on MacOS. With Homebrew, the commands would be brew install [boost, mako, etc]
. If you find you've installed something not necessary, you can use brew uninstall [library name]
and brew list
to discover what libraries brew has installed.
Another necessary adjustment are the flags. Use cmake -DENABLE_PYTHON_API=ON
to enable the python API as well as the C ones. Use the flag -DENABLE_C_API=OFF
if the C/C++ APIs are not necessary.
If the tests are not disabled when running cmake, running make tests
in the build
directory will test the installation for problems. They should all pass.
When running the command make -j8
, it is possible too much memory will be used, causing the command to fail partway through. Simply reduce the number of processes (i.e. make -j4
) if necessary. This command will take a long time to execute, so getting it right is critical.
Debug
Once you have run the command make install
from the tutorials, in theory you are done. This was not our experience; it seemed configuration issues with python and non-standard installation locations were the problem. You can test this by running python3 in the shell and trying
import uhd
radio = uhd.usrp.MultiUSRP()
This will reveal the issue.
Possible solutions:
First, since the command line interface is installed in the ~
directory, running python from the home directory will find that folder when importing uhd rather than the homonymous package directory located somewhere in your python site packages folders. You can fix this (in an admittedly hacky way) by inserting the location the package was installed in into the first part of sys.path
, like so:
import sys
sys.path.insert(0, "/path/to/module")
There is definitely a permanent way to do this, but we didn't look into it.
Second, the library will possibly not be fully loaded. This could have something to do with the Python installation. For us, , running the module's __init__.py
file as importing does resulted in an error: 'Could not find libpython.dylib'. We found that file for our installation using the find / -type f -name libpython
command in the shell and choosing the appropriate file (because Python was installed via brew, this was in the Cellar). We then used `ln -s to place a symbolic link the interpreter could follow when running the import.