由于在Ubuntu18.04下ROS Melodic是运行在python 2.7环境下,而我的程序需要运行在anaconda创建的python 3.x环境里,这就需要用到cv_bridge这个库,而不出意外的,各种报错,比如:
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)
在今年上半年,我的解决方法是:完全参考下面的两两篇博客:
安装CV_bridge Ubuntu18.04+Melodic+Python3 - 知乎
ROS——在Ubuntu18.04下基于ROS Melodic编译python3的cv_bridge_ros melodic python3 cv_bridge_Irving.Gao的博客-CSDN博客
但今天在一台新电脑上用同样的方法,一直在编译的时候报错:
CMake Error: File /home/sjh/project/ros_cv_bridge/src/package.xml does not exist.
CMake Error at /opt/ros/melodic/share/catkin/cmake/stamp.cmake:10 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
/opt/ros/melodic/share/catkin/cmake/catkin_package_xml.cmake:72 (stamp)
/opt/ros/melodic/share/catkin/cmake/catkin_package_xml.cmake:50 (_catkin_package_xml)
/opt/ros/melodic/share/catkin/cmake/catkin_package.cmake:99 (catkin_package_xml)
CMakeLists.txt:12 (catkin_package)
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkin_package.cmake:116 (message):
catkin_package() 'catkin' must be listed as a buildtool dependency in the
package.xml
Call Stack (most recent call first):
/opt/ros/melodic/share/catkin/cmake/catkin_package.cmake:102 (_catkin_package)
CMakeLists.txt:12 (catkin_package)
-- Configuring incomplete, errors occurred!
See also "/home/sjh/project/ros_cv_bridge/build/CMakeFiles/CMakeOutput.log".
See also "/home/sjh/project/ros_cv_bridge/build/CMakeFiles/CMakeError.log".
Invoking "cmake" failed
换了多种方法,无解,但想到,在上面的教程中,使用的是catkin_make install指令,按道理说,这个指令中得到的install文件夹,在相同系统和架构的设备上是通用的,因此打算从另一台电脑上搬过来
下面开始过程:
注意:仅适用于X86架构的Ubuntu18.04+ROS Melodic环境下,其他环境,请继续参考文章开始提到的教程
一、下载install文件
百度网盘链接:https://pan.baidu.com/s/1Q6rChZHTbMvdutUgQzNDPQ?pwd=wxng
提取码: wxng
或者在CSDN资源中下载:https://download.csdn.net/download/weixin_45498383/88563843
二、解压install文件
上一步中下载下来的是一个压缩包,将其解压在一个文件夹内即可,想我就解压在了
~/project/ros_cv_bridge/install
目录下,要记住这个目录,后面要用的
三、修改.bashrc文件
打开.bashrc文件,在文末添加如图内容:
source ~/project/ros_cv_bridge/install/setup.bash --extend
然后关掉文件,关掉你的终端,重新打开,再进行测试,发现已经不再报错了,cv_bridge运行正常
注意:仅适用于X86架构的Ubuntu18.04+ROS Melodic环境下,其他环境,请继续参考文章开始提到的教程