本文介绍了安装ROS Kinetic后,无法导入OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先使用此脚本从源代码安装了openCV.当我测试时,它运行良好.

I have first installed openCV from source using this script.When I tested it was working well.

在安装 ROS动力学之后,打开python3并运行import cv2 ,出现以下错误:

After I installed ROS kinetic, and open python3 and run import cv2, got the following error:

Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type

推荐答案

似乎此问题是由ROS将/opt/ros/kinetic/lib/python2.7/dist-packages添加到python路径引起的.当您使用命令source /opt/ros/kinetic/setup.bash激活ROS时,实际上会发生这种情况.此行通常添加在bashrc文件的末尾,在/home/username/.bashrc中.

It looks like this problem is caused by ROS adding /opt/ros/kinetic/lib/python2.7/dist-packages to the python path. This actually happens when you activate ROS with the command source /opt/ros/kinetic/setup.bash. This line is often added at the end of your bashrc file, in /home/username/.bashrc.

一种解决方法是从bashrc文件中删除此行.这样,python3 opencv软件包将被正确使用,并且您仍然可以运行source /opt/ros/kinetic/setup.bash来使用ROS.但是,这确实意味着您不能在同一环境中使用ROS和python3.

A workaround is to remove this line from the bashrc file. This way the python3 opencv packages will be correctly used, and you can still run source /opt/ros/kinetic/setup.bash to use ROS. However, this does mean you cannot use ROS and python3 from the same environment.

希望有人能提供更好的答案,但这应该在那之前起作用.

Hopefully someone can come up with a better answer, but this should work until then.

这篇关于安装ROS Kinetic后,无法导入OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 05:50