how to install cvbridge (python version)?

asked 2020-04-12 02:57:00 -0500

resplendent star gravatar image

updated 2020-04-12 04:48:24 -0500

gvdhoorn gravatar image

hello,when I run code ,occur such error

ubuntu 1804, ros-melodic

Traceback (most recent call last):
  File "/home/lzw/resplendent_code/voxblox_pp_ws/src/mask_rcnn_ros/scripts/", line 9, in <module>
    from cv_bridge import CvBridge
ImportError: No module named cv_bridge

and if I execute this command sudo -H pip3 install cv_bridge

i get

Collecting cv_bridge
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/", line 215, in main
    status =, args)
  File "/usr/lib/python3/dist-packages/pip/commands/", line 353, in run
  File "/usr/lib/python3/dist-packages/pip/", line 749, in build
  File "/usr/lib/python3/dist-packages/pip/req/", line 380, in prepare_files
  File "/usr/lib/python3/dist-packages/pip/req/", line 554, in _prepare_file
  File "/usr/lib/python3/dist-packages/pip/req/", line 278, in populate_link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python3/dist-packages/pip/", line 465, in find_requirement
    all_candidates = self.find_all_candidates(
  File "/usr/lib/python3/dist-packages/pip/", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python3/dist-packages/pip/", line 568, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python3/dist-packages/pip/", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python3/dist-packages/pip/", line 795, in get_page
  File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url:
edit retag flag offensive close merge delete


Hi @resplendent star,

Why not install the dependency from the precompiled binaries with apt?

sudo apt-get install ros-$(rosversion -d)-cv-bridge
Weasfas gravatar image Weasfas  ( 2020-04-12 05:42:30 -0500 )edit

hi,i have already use this command to install cvbridge,but still will get the error that i post above

if i use sudo apt-get install i will get

lzw@resplendent-star:~/3d_lib/pycharm-2019.3.3/bin$ sudo apt-get install ros-$(rosversion -d)-cv-bridge [sudo] lzw 's password: 正在读取软件包列表... done 正在分析软件包的依赖关系树
正在读取状态信息... done
ros-melodic-cv-bridge is the latest version(1.13.0-0bionic.20200320.133849)。

resplendent star gravatar image resplendent star  ( 2020-04-12 08:27:02 -0500 )edit

Mmm, probably the issue is that cv_bridge is built only for python 2.7 and you are using python 3 interpreter, that is the default for ROS Melodic. Since the interpreter is trying to use cv_bridge for 2.7 will always fails for Python 3.

To solve it you can try to install:

sudo apt-get install python-catkin-tools python3-dev

and then create a new catkin_ws configured to use your Python 3.XX version. That can be done by:

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
cd ~/catkin_ws
catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/
catkin config --install

Please note this assumes a Python 3.6 version.

Weasfas gravatar image Weasfas  ( 2020-04-12 10:47:51 -0500 )edit

thanks for reply,how to install cvbridge with conda?:)

resplendent star gravatar image resplendent star  ( 2020-04-13 07:14:28 -0500 )edit

Well, as you may notice, this forum is for ROS problems and issues, unfortunatelly you question is out of the scope of the forum so you probably want to ask it in a more suitable place. However, just perform a quick search and you will end in wiki pages like this.

Weasfas gravatar image Weasfas  ( 2020-04-13 13:40:33 -0500 )edit