python-onvif 库踩坑
python2环境
时间:2021年6月
操作系统:ubuntu 18.04
参考博客:
https://blog.csdn.net/zong596568821xp/article/details/89644654
使用了conda用于环境隔离
新建环境:
conda create --name py2 python=2.7
使用环境:
conda activate py2
安装onvif包:
pip install onvif
或者源码安装
git clone https://github.com/quatanium/python-onvif
cd python-onvif
python setup.py install
执行样例代码出现如下错误:
Traceback (most recent call last):
File "pic.py", line 84, in <module>
continuous_move()
File "pic.py", line 44, in continuous_move
mycam = ONVIFCamera('192.168.1.30', 80, 'video', 'hk123456')
File "/home/lzh/anaconda3/envs/py2/lib/python2.7/site-packages/onvif/client.py", line 258, in __init__
self.update_xaddrs()
File "/home/lzh/anaconda3/envs/py2/lib/python2.7/site-packages/onvif/client.py", line 265, in update_xaddrs
self.devicemgmt = self.create_devicemgmt_service()
File "/home/lzh/anaconda3/envs/py2/lib/python2.7/site-packages/onvif/client.py", line 393, in create_devicemgmt_service
return self.create_onvif_service('devicemgmt', from_template)
File "/home/lzh/anaconda3/envs/py2/lib/python2.7/site-packages/onvif/client.py", line 362, in create_onvif_service
xaddr, wsdl_file = self.get_definition(name)
File "/home/lzh/anaconda3/envs/py2/lib/python2.7/site-packages/onvif/client.py", line 344, in get_definition
raise ONVIFError('No such file: %s' % wsdlpath)
onvif.exceptions.ONVIFError: Unknown error: No such file: /home/lzh/anaconda3/envs/py2/lib/python2.7/site-packages/wsdl/devicemgmt.wsdl
原因:
wsdl文件夹在安装的时候被复制到了
/home/用户名/anaconda3/envs/py2/wsdl
目录下
解决方法:
复制上述目录的wsdl文件夹到路径
/home/用户名/anaconda3/envs/py2/lib/python2.7/site-packages/
下即可。