Documentation:
http:// https://pyrtlsdr.readthedocs.io
安装好pyrtldr库(pip insall ……)后,验证代码如下:
from rtlsdr import RtlSdr
sdr = RtlSdr()
# configure device
sdr.sample_rate = 2.048e6 # Hz
sdr.center_freq = 70e6 # Hz
sdr.freq_correction = 60 # PPM
sdr.gain = 'auto'
print(sdr.read_samples(512))
报错(ImportError: Error loading librtlsdr. Make sure librtlsdr (and all of its dependencies) are in your path):
Traceback (most recent call last):
File "D:\VScode\Rtlsdr\try1.py", line 2, in <module>
from rtlsdr import RtlSdr
File "D:\App\Cuda\conda\lib\site-packages\rtlsdr\__init__.py", line 56, in <module>
from .librtlsdr import librtlsdr
File "D:\App\Cuda\conda\lib\site-packages\rtlsdr\librtlsdr.py", line 50, in <module>
librtlsdr = load_librtlsdr()
File "D:\App\Cuda\conda\lib\site-packages\rtlsdr\librtlsdr.py", line 45, in load_librtlsdr
raise ImportError('Error loading librtlsdr. Make sure librtlsdr '\
ImportError: Error loading librtlsdr. Make sure librtlsdr (and all of its dependencies) are in your path
原因:
1.没有在目录文件(文件配置环境)下放入相关的硬件驱动文件(加密狗)
文件相关链接:RTL utils
2.头文件内某些相对路径改为绝对路径
# driver_files += ['librtlsdr.so', 'rtlsdr/librtlsdr.so']
# driver_files += ['rtlsdr.dll', 'librtlsdr.so']
# driver_files += ['..//rtlsdr.dll', '..//librtlsdr.so']
# driver_files += ['rtlsdr//rtlsdr.dll', 'rtlsdr//librtlsdr.so']
# driver_files += [lambda : find_library('rtlsdr'), lambda :find_library('librtlsdr')]
driver_files += ['D:\\App\\Cuda\\conda\\Lib\\site-packages\\rtlsdr\\librtlsdr.dll']
driver_files += ['D:\\App\\Cuda\\conda\\Lib\\site-packages\\rtlsdr\\libusb-1.0.dll']
driver_files += ['D:\\App\\Cuda\\conda\\Lib\\site-packages\\rtlsdr\\libwinpthread-1.dll']
完成相关步骤后,若再次报错(AttributeError: function 'rtlsdr_get_device_count' not found):
Traceback (most recent call last):
File "D:\VScode\Rtlsdr\try1.py", line 2, in <module>
from rtlsdr import *
File "D:\App\Cuda\conda\lib\site-packages\rtlsdr\__init__.py", line 56, in <module>
from .librtlsdr import librtlsdr
File "D:\App\Cuda\conda\lib\site-packages\rtlsdr\librtlsdr.py", line 64, in <module>
f = librtlsdr.rtlsdr_get_device_count
File "D:\App\Cuda\conda\lib\ctypes\__init__.py", line 395, in __getattr__
func = self.__getitem__(name)
File "D:\App\Cuda\conda\lib\ctypes\__init__.py", line 400, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'rtlsdr_get_device_count' not found
原因:
pyrtlsdr库本地安装时可能安装的不完整,需重新安装
链接:Releases · librtlsdr/librtlsdr · GitHub
我选择的是rtlsdr-bin-w64_static.zip,复制粘贴到配置环境文件夹(D:\App\Cuda\conda\lib\site-packages\rtlsdr)中
参考文献(大多需翻墙):