How to solve AttributeError: module 'uhd' has no attribute 'usrp'

1.4k Views Asked by At

I know it is a wide answered question, however, I could solve it. When I'm trying to execute the command

usrp = uhd.usrp.MultiUSRP()

from https://pysdr.org/content/usrp.html I get this error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'uhd' has no attribute 'usrp'

I've executed:

export PYTHONPATH="/usr/local/lib/python3.8/site-packages/"

Inside lib I have:

/use/local/lib/python3.8/site-packages$ ls
uhd usrp_mpm

Inside uhd there are the following files (including usrp):

/usr/local/lib/python3.8/site-packages/uhd$ ls
chdr.py     imgbuilder                               property_tree.py  usrp
dsp         __init__.py                              rfnoc.py          usrpctl
filters.py  libpyuhd.cpython-38-x86_64-linux-gnu.so  types.py          utils

And inside usrp:

/usr/local/lib/python3.8/site-packages/uhd/usrp$ ls
cal  __init__.py  libtypes.py  multi_usrp.py

The version of python is:

Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

The SO is:

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:    20.04
Codename:   focal

Anything missing?

2

There are 2 best solutions below

0
Amelia Yang On

I met the same problem as you, but now what I have found is the Python path issue.

Open bashrc file in the terminal :

gedit ~/.bashrc

At the end of the file, add up the UHD path:

export PYTHONPATH=/usr/local/lib/python3/dist-packages/:/usr/local/lib/python3.8/sitepackages/:$PYTHONPATH

Save and close bashrc file, back to the terminal:

source ~/.bashrc

Then restart your host and test:

import uhd.usrp
0
Dandymon On

For my install, it was being funny that the UHD library wasn't installed in /usr/local/lib/python3.10/dist-packages, but was in /usr/local/lib/python3.10/site-packages. I'm not an expert in the land of python and env variables, so I just copied the library to dist-packages and it works fine

sudo cp /usr/local/lib/python3.10/site-packages/* /usr/local/lib/python3.10/dist-packages/ -r

(prepares for a barrage of "you shouldn't do that.." comments)