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/mask_rcnn_node.py", 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
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python3/dist-packages/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python3/dist-packages/pip/index.py", line 795, in get_page
    resp.raise_for_status()
  File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/cv-bridge/
edit retag flag offensive close merge delete

Comments

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
catkin_init_workspace
cd ~/catkin_ws
catkin_make
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
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