解决安装ROS后,ubuntu中python3不能import cv2的问题

报错如下:

Python 3.5.2 (default, Jan 26 2021, 13:30:48) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "", line 1, in 
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type

解决方法:

//来到cv2.so的路径下
cd /opt/ros/kinetic/lib/python2.7/dist-packages
//将cv2.so备份一份为cv2.so.back(也可不备份)
sudo cp -i cv2.so /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so.backup
//将cv2.so重命名为cv2_ros.so(使其找不到cv2.so)
sudo mv cv2.so cv2_ros.so

你可能感兴趣的:(ubuntu,linux,opencv,python)