2

I build uhd in windows (msvc 14.2, boost 1.72.0). Build works fine. I can run all of the command line utilities (eg rx_samples_from_file) without error.

But in python I cannot import uhd:

>>> import sys
>>> sys.path.append('C:\\Program Files (x86)\\UHD\\bin')
>>> sys.path.append('C:\\Program Files (x86)\\UHD\\lib')
>>> sys.path.append('C:\\Program Files (x86)\\UHD\\lib\\site-packages')
>>> sys.path.append('C:\\local\\boost_1_72_0\\lib64-msvc-14.2')
>>> sys.path.append('C:\\lib\\libusb-1.0.22\\MS64\\dll')
>>> import uhd

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files (x86)\UHD\lib\site-packages\uhd\__init__.py", line 10, in <module>
    from . import types
  File "C:\Program Files (x86)\UHD\lib\site-packages\uhd\types.py", line 10, in <module>
    from . import libpyuhd as lib
ImportError: DLL load failed while importing libpyuhd: The specified module could not be found.

Is there anyway to tell which DLL is not loading? I tried using dependency walker on libpyuhd but it did not show anything missing.

b0fh
  • 1,678
  • 12
  • 28
Mike Line
  • 21
  • 1

1 Answers1

0

I had a similar issue, in that I could access the hardware via command line utilities or through GnuRadio Companion, but not directly through python (even though GRC is only launching the python files using the same python interpreter). I kept having these DLL issues.

Turns out that the location in sys.path are used by python to look for modules, but if the modules themselves are relying on .dll files, then they use the locations in the environmental variable path. I guess that the fetching of DLLS is handled directly by the OS and not by Python.

You can see the location in Python with os.environ['PATH'] . It should be the same list as by typing PATH the windows command line.

I solved the problem by crating a batch file that added the directories to the path before running python. In your case, you could try adding the directories to it (you would have to see which ones are missing):

@ECHO off
SET PATH=%PATH%;C:\\Program Files (x86)\\UHD\\bin;C:\\Program Files (x86)\\UHD\\lib;C:\\lib\\libusb-1.0.22\\MS64\\dll

python your_python_script.py

the path will be temporarily changed, (don't forget the %PATH% so that it appends the new folders to it) and once you exit the batch file, it will restore back to the default value.

You could also permanently change the path, by going to System Properties → Advanced → Environment variables.

XaC
  • 432
  • 3
  • 9