发布时间:2023-12-27 14:30
在Ubuntu16.04上先后安装了Anaconda和ROS,然后在anaconda配置的pytorch环境中运行python代码,在import cv2报错,如下:
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
在代码中,在import cv2之前,将sys.path中的“/opt/ros/kinetic/lib/python2.7/dist-packages”去掉:
//
import sys
ros_cv2_path='/opt/ros/kinetic/lib/python2.7/dist-packages'
if ros_cv2_path in sys.path:
sys.path.remove(ros_cv2_path)
之后再import cv2 就可以了。
参考博客
[1]: https://blog.csdn.net/qq_34544129/article/details/81946494
[2]: https://www.cnblogs.com/long5683/p/12915782.html