python3报错:importError: dynamic module does not define module export function (PyInit_cv_bridge_boost

1 在使用python3调用cv_bridge报错
1、在使用python3调用cv_bridge报错:importError: dynamic module does not define module export function (PyInit_cv_bridge_boost)

2、解决方式(参考)

# `python-catkin-tools` is needed for catkin tool
# `python3-dev` and `python3-catkin-pkg-modules` is needed to build cv_bridge
# `python3-numpy` and `python3-yaml` is cv_bridge dependencies
# `ros-kinetic-cv-bridge` is needed to install a lot of cv_bridge deps. Probaply you already have it installed.
sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-kinetic-cv-bridge
# Create catkin workspace
mkdir catkin_workspace
cd catkin_workspace
catkin init
# Instruct catkin to set cmake variables
catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.5m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so
# Instruct catkin to install built packages into install place. It is $CATKIN_WORKSPACE/install folder
catkin config --install
# Clone cv_bridge src
git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv
# Find version of cv_bridge in your repository
apt-cache show ros-kinetic-cv-bridge | grep Version
    Version: 1.12.8-0xenial-20180416-143935-0800
# Checkout right version in git repo. In our case it is 1.12.8
cd src/vision_opencv/
git checkout 1.12.8
cd ../../
# Build
catkin build cv_bridge
# Extend environment with new package
source install/setup.bash --extend


注意:

1、如果打开一个新的终端,需要再source一次,如果不想每次python3使用都source,就可以将其添加到~/.bashrc环境变量中

shl@zhihui-mint:~/tools/catkin_cv_bridge_ws$ source install/setup.bash --extend
shl@zhihui-mint:~/tools/catkin_cv_bridge_ws$ python3
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cv_bridge.boost.cv_bridge_boost import getCvType

2、如果要用python2继续使用cv_bridge,就不需要source了!
 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在你的错误信息中,ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost),这可能是由于ROS自带的cv_bridge只支持Python2而不是Python3导致的。为了解决这个问题,你需要编译一个适用于Python3cv_bridge模块。 以下是解决方案: 1. 首先,确保你在系统的真实环境中操作,而不是在conda创建的虚拟环境中。打开一个新终端,并运行conda deactivate命令,确保退出所有虚拟环境。 2. 进入Python3环境并安装相关依赖包: ``` sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-melodic-cv-bridge ``` 注意,根据你使用的ROS版本可能会有略微不同的依赖包名称。 3. 创建一个工作空间用于存放待编译的cv_bridge文件: ``` mkdir -p catkin_ws_for_cvbridge/src ``` 4. 设置参数: ``` cd catkin_ws_for_cvbridge catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so ``` 注意,这里的参数根据你系统自带的Python版本进行设置,16.04使用Python3.5,18.04使用Python3.6。 5. 告诉catkin将构建的包安装到指定位置: ``` catkin config --install ``` 6. 在catkin_workspace工作空间中克隆cv_bridge: ``` git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv ``` 7. 查看适合的cv_bridge版本: ``` apt-cache show ros-melodic-cv-bridge | grep Version ``` 8. 编译cv_bridge: ``` catkin build cv_bridge ``` 如果一切顺利,应该能够成功编译cv_bridge模块。 9. 最后,确保你将编译后的cv_bridge包添加到ROS的环境变量中。 通过以上步骤,你应该能够解决ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [在Python3环境中使用ROS的cv_bridge](https://download.csdn.net/download/weixin_38703794/14036198)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【bug】ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)](https://blog.csdn.net/qq_36497369/article/details/128853820)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值