6

My python code gives this error:

from cv_bridge import CvBridge, CvBridgeError

ImportError: libcv_bridge.so: cannot open shared object file: No such file or directory.

However if I do a ldd, every thing seems fine. What is wrong? (ROS indigo, ubuntu 14.04 LTS, PyCharm)

user@user-VirtualBox:/opt/ros/indigo/lib$ ldd libcv_bridge.so
linux-vdso.so.1 =>  (0x00007ffc9439d000)
libopencv_imgproc.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4 (0x00007fcac6b34000)
libopencv_highgui.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4 (0x00007fcac68e9000)
libopencv_core.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4 (0x00007fcac64b1000)
libopencv_contrib.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_contrib.so.2.4 (0x00007fcac61ce000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fcac5eca000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fcac5cb3000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcac58ee000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcac56d0000)
libtbb.so.2 => /usr/lib/libtbb.so.2 (0x00007fcac549b000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fcac5195000)
libGL.so.1 => /var/lib/VBoxGuestAdditions/lib/libGL.so.1 (0x00007fcac4f5d000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007fcac4d07000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007fcac4ae1000)
libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007fcac486f000)
libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007fcac4617000)
libIlmImf.so.6 => /usr/lib/x86_64-linux-gnu/libIlmImf.so.6 (0x00007fcac4368000)
libHalf.so.6 => /usr/lib/x86_64-linux-gnu/libHalf.so.6 (0x00007fcac4125000)
libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007fcac3ae7000)
libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007fcac3834000)
libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007fcac35e3000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fcac32da000)
libgtkglext-x11-1.0.so.0 => /usr/lib/libgtkglext-x11-1.0.so.0 (0x00007fcac30d6000)
libgdkglext-x11-1.0.so.0 => /usr/lib/libgdkglext-x11-1.0.so.0 (0x00007fcac2e72000)
libdc1394.so.22 => /usr/lib/x86_64-linux-gnu/libdc1394.so.22 (0x00007fcac2bfd000)
libv4l1.so.0 => /usr/lib/x86_64-linux-gnu/libv4l1.so.0 (0x00007fcac29f7000)
libavcodec.so.54 => /usr/lib/x86_64-linux-gnu/libavcodec.so.54 (0x00007fcac1ca3000)
libavformat.so.54 => /usr/lib/x86_64-linux-gnu/libavformat.so.54 (0x00007fcac1980000)
libavutil.so.52 => /usr/lib/x86_64-linux-gnu/libavutil.so.52 (0x00007fcac175b000)
libswscale.so.2 => /usr/lib/x86_64-linux-gnu/libswscale.so.2 (0x00007fcac1514000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fcac12fa000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fcac10f2000)
libopencv_features2d.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_features2d.so.2.4 (0x00007fcac0e4e000)
libopencv_calib3d.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.2.4 (0x00007fcac0bb8000)
libopencv_ml.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_ml.so.2.4 (0x00007fcac0940000)
libopencv_objdetect.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so.2.4 (0x00007fcac06c5000)
libopencv_video.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_video.so.2.4 (0x00007fcac0471000)
/lib64/ld-linux-x86-64.so.2 (0x0000560365edd000)
VBoxOGLcrutil.so => /usr/lib/x86_64-linux-gnu/VBoxOGLcrutil.so (0x00007fcac028e000)
libXcomposite.so.1 => /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007fcac008b000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007fcabfe88000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007fcabfc81000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fcabfa6f000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fcabf86b000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fcabf648000)
libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007fcabf43a000)
libIex.so.6 => /usr/lib/x86_64-linux-gnu/libIex.so.6 (0x00007fcabf21c000)
libIlmThread.so.6 => /usr/lib/x86_64-linux-gnu/libIlmThread.so.6 (0x00007fcabf015000)
libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007fcabee11000)
libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007fcabec04000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fcabe8ce000)
libatk-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007fcabe6ac000)
libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007fcabe3a1000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007fcabe17f000)
libgio-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007fcabde0c000)
libpangoft2-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007fcabdbf7000)
libpango-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007fcabd9a9000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007fcabd76d000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007fcabd562000)
libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007fcabd35f000)
libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007fcabd14f000)
libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007fcabcf45000)
libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007fcabcd3a000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fcabcb32000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fcabc8f3000)
libGLU.so.1 => /usr/lib/x86_64-linux-gnu/libGLU.so.1 (0x00007fcabc685000)
libXmu.so.6 => /usr/lib/x86_64-linux-gnu/libXmu.so.6 (0x00007fcabc46c000)
libpangox-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangox-1.0.so.0 (0x00007fcabc24c000)
libraw1394.so.11 => /usr/lib/x86_64-linux-gnu/libraw1394.so.11 (0x00007fcabc03e000)
libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007fcabbe27000)
libv4l2.so.0 => /usr/lib/x86_64-linux-gnu/libv4l2.so.0 (0x00007fcabbc18000)
libxvidcore.so.4 => /usr/lib/x86_64-linux-gnu/libxvidcore.so.4 (0x00007fcabb8da000)
libx264.so.142 => /usr/lib/x86_64-linux-gnu/libx264.so.142 (0x00007fcabb544000)
libvpx.so.1 => /usr/lib/x86_64-linux-gnu/libvpx.so.1 (0x00007fcabb164000)
libvorbisenc.so.2 => /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007fcabac95000)
libvorbis.so.0 => /usr/lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007fcabaa68000)
libtheoraenc.so.1 => /usr/lib/x86_64-linux-gnu/libtheoraenc.so.1 (0x00007fcaba827000)
libtheoradec.so.1 => /usr/lib/x86_64-linux-gnu/libtheoradec.so.1 (0x00007fcaba60e000)
libspeex.so.1 => /usr/lib/x86_64-linux-gnu/libspeex.so.1 (0x00007fcaba3f5000)
libschroedinger-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libschroedinger-1.0.so.0 (0x00007fcaba130000)
libopus.so.0 => /usr/lib/x86_64-linux-gnu/libopus.so.0 (0x00007fcab9ee8000)
libopenjpeg.so.2 => /usr/lib/x86_64-linux-gnu/libopenjpeg.so.2 (0x00007fcab9cc6000)
libmp3lame.so.0 => /usr/lib/x86_64-linux-gnu/libmp3lame.so.0 (0x00007fcab9a38000)
libgsm.so.1 => /usr/lib/x86_64-linux-gnu/libgsm.so.1 (0x00007fcab982a000)
libva.so.1 => /usr/lib/x86_64-linux-gnu/libva.so.1 (0x00007fcab9614000)
librtmp.so.0 => /usr/lib/x86_64-linux-gnu/librtmp.so.0 (0x00007fcab93f9000)
libgnutls.so.26 => /usr/lib/x86_64-linux-gnu/libgnutls.so.26 (0x00007fcab913b000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007fcab8f2b000)
libopencv_flann.so.2.4 => /usr/lib/x86_64-linux-gnu/libopencv_flann.so.2.4 (0x00007fcab8cc0000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fcab8a1c000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fcab87fd000)
libpixman-1.so.0 => /usr/lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007fcab8554000)
libxcb-shm.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007fcab8351000)
libxcb-render.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007fcab8148000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fcab7f24000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fcab7d09000)
libharfbuzz.so.0 => /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007fcab7ab4000)
libthai.so.0 => /usr/lib/x86_64-linux-gnu/libthai.so.0 (0x00007fcab78aa000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fcab7680000)
libXt.so.6 => /usr/lib/x86_64-linux-gnu/libXt.so.6 (0x00007fcab7419000)
libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007fcab7208000)
libv4lconvert.so.0 => /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0 (0x00007fcab6f8f000)
libogg.so.0 => /usr/lib/x86_64-linux-gnu/libogg.so.0 (0x00007fcab6d85000)
liborc-0.4.so.0 => /usr/lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x00007fcab6b03000)
libgcrypt.so.11 => /lib/x86_64-linux-gnu/libgcrypt.so.11 (0x00007fcab6882000)
libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007fcab666e000)
libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007fcab642c000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fcab6227000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fcab6021000)
libgraphite2.so.3 => /usr/lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007fcab5dfa000)
libdatrie.so.1 => /usr/lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007fcab5bf3000)
libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007fcab59eb000)
libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007fcab57ce000)
libcgmanager.so.0 => /lib/x86_64-linux-gnu/libcgmanager.so.0 (0x00007fcab55b3000)
libnih.so.1 => /lib/x86_64-linux-gnu/libnih.so.1 (0x00007fcab539b000)
libnih-dbus.so.1 => /lib/x86_64-linux-gnu/libnih-dbus.so.1 (0x00007fcab5190000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007fcab4f4b000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007fcab4d45000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007fcab4b40000)

3 Answers 3

6

You need to export the relevant LD LIBRARY path and add it in your bash profile file as in this example:

Python executable not finding libpython shared library

Sign up to request clarification or add additional context in comments.

1 Comment

This works like a charm, but could you explain why, or some documents around it? I can't understand the comments in the SO you linked. Thanks!
4

i add LD_LIBRARY_PATH at the pycharm setting:

enter image description here

Comments

0

I've been struggling with this for about a day now, and this is the SO question that kept coming up in my feed.

PyCharm does not respect the shell environment variable for LD_LIBRARY_PATH; you can confirm this with the following:

import os

print(os.environ['LD_LIBRARY_PATH'])

You'll get a key error because PyCharm hasn't used what you've got set. In my case, I also tried to get cv_bridge to work with a pip install cv_bridge, but I believe this pulls the ROS1 version of cv_bridge. You don't need to do anything to get cv_bridge, so you should probably go on and pip uninstall cv_bridge.

Now you'll go back to PyCharm complaining that no such module exists for cv_bridge, but again it's because it doesn't know how to find it.

If you follow other answers, you may be tempted to go to Settings > Build, Execution, Deployment > Console > Python Console and edit the Environment variables there. This option is what comes up when you search 'environment variable' in settings, but this is not doing anything for you. This sets the environment variables in the console, it doesn't affect anything for pushing the play/run button. Don't believe me? Try setting something there and then running the above snippet again, and again you'll get a key error.

The thing that escaped me in Op's own answer above is that the screen they've got up is for the Run/Debug Configurations page. You don't get to this page through settings, you click the dropdown beside the play/run button. If it just says "Current File" then you'll need to click it, click "Edit Configurations," then "Add new run configuration..." and pick Python. Be sure to set your script path in the box beside script so PyCharm knows what to execute when you hit play/run. Under this you'll get a box for Environment variables, and HERE is where you can set something like LD_LIBRARY_PATH=/opt/ros/iron/lib, etc.

Doing this still didn't solve it for me, though, but it did get Python to recognize the LD_LIBRARY_PATH settings.

Ultimately it's yet another setting: Settings > Project: > Project Structure. On the right pane, you'll want to click + Add Content Root and then browse to your /opt/ros/iron/lib/pythonX.Y/site-packages folder.

Once you've added the folder here you should be good to go. If you get a message about something like missing sensor_msgs, again check if you pip installed the bridge with pip show cv_bridge. If that comes back with a package, again I believe it's the ROS1 version and you're not going to want that. You can double-check the path there, but it's probably in your ~/.local/lib/pythonX.Y/site-packages folder, which is not what you want for your version of ROS. pip uninstall cv_bridge and use what you've got from your /opt/ros location.

:EDIT: To be clear, you need BOTH the LD_LIBRARY_PATH environment variable set in your run config AND the content root set.

  1. If you set the LD_LIBRARY_PATH environment variable without having the content root set, you'll see ModuleNotFoundError: No module named 'cv_bridge'
  2. If you set the content root without having the environment variable set, you'll see libcv_bridge.so: cannot open shared object file: No such file or directory

You need BOTH set to get this to work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.