View my account

Raspberry Pi ModuleNotFoundError: No module named 'pyrealsense2'

Comments

51 comments

  • MartyG

    Hi Cnorton  Pip install of pyrealsense2 will not work with Raspberry Pi unfortunately, because the pip packages for pyrealsense2 require x86 or x64 processors, and the Pi's processor is Arm (not 'x' architecture).

    When building librealsense from source with CMake, you can build pyrealsense2 along with it by including the BUILD_PYTHON_BINDINGS instruction in the CMake statement to build pyrealsense2.

    -DBUILD_PYTHON_BINDINGS=bool:true

    For example, to build librealsense and pyrealsense2 from source over an internet connection in a single action without the need to patch:

     

    cmake ../ -DFORCE_RSUSB_BACKEND=true -DBUILD_PYTHON_BINDINGS=bool:true -DCMAKE_BUILD_TYPE=release -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true

    0
    Comment actions Permalink
  • Cnorton

    Hi MartyG,

    Looks like that built:

    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/pi/Desktop/librealsense-master/librealsense-master/wrappers

    however when I try running the python file I get the same error:

    ModuleNotFoundError: No module named 'pyrealsense2'

    0
    Comment actions Permalink
  • MartyG

    After you compiled Pyrealsense2, did you update your PYTHONPATH please with the command below?

    export PYTHONPATH=$PYTHONPATH:/usr/local/lib

    0
    Comment actions Permalink
  • Cnorton

    sorry got a little ahead of myself. the cmake command you gave me worked, but then I just ran make -j4 and got this:

    [ 13%] Linking CXX static library librealsense-file.a
    [ 13%] Built target realsense-file
    make: *** [Makefile:130: all] Error 2

    There were a ton of warnings and I think I saw the config.h error again (went over the terminal line limit to look at what the error was).

    0
    Comment actions Permalink
  • Cnorton

    Yeah when I run sudo make install I get: 

    fatal error: config.h: No such file or directory
    #include "config.h"
    ^~~~~~~~~~
    compilation terminated.
    make[5]: *** [CMakeFiles/usb.dir/build.make:63: CMakeFiles/usb.dir/libusb/core.c.o] Error 1
    make[4]: *** [CMakeFiles/Makefile2:73: CMakeFiles/usb.dir/all] Error 2
    make[3]: *** [Makefile:130: all] Error 2
    make[2]: *** [CMakeFiles/libusb.dir/build.make:112: libusb-prefix/src/libusb-stamp/libusb-build] Error 2
    make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/libusb.dir/all] Error 2
    make: *** [Makefile:130: all] Error 2

    When I do a directory search, there's like 8 different config files. Which one am I looking for?

    0
    Comment actions Permalink
  • MartyG

    As far as I know, it should not be necessary to use make -j4 with the internet-based RSUSB method of building from source.  Are you able to set the pythonpath?

    1
    Comment actions Permalink
  • Cnorton

    huh alright, well I ran

    cmake ../ -DFORCE_RSUSB_BACKEND=true -DBUILD_PYTHON_BINDINGS=bool:true -DCMAKE_BUILD_TYPE=release -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true

    and 
    export PYTHONPATH=$PYTHONPATH:/usr/local/lib

    I ran which python3 and got: /usr/bin/python3

    usr/local/lib does not have python3, but does have python2.7 and python 3.7
    am I missing a step?

    0
    Comment actions Permalink
  • MartyG

    Re-reading the case from the start, the problem may be that the OS being used is Raspbian and not Ubuntu.  In which case, a special procedure to install the Python wrapper may be needed.  I do apologise.

    Are you using Pi 3b or Pi 4 please?

    0
    Comment actions Permalink
  • Cnorton

    I am using a Pi 4 (4GB if that matters)

    0
    Comment actions Permalink
  • MartyG

    I hope that the guide in the link below will help you to overcome the module not found error on Raspbian.

    https://github.com/IntelRealSense/librealsense/issues/4375 

    0
    Comment actions Permalink
  • Cnorton

    Went through everything in that link and changed the CMakeList files. Still have the same issue.

    0
    Comment actions Permalink
  • MartyG

    The link below is Intel's own librealsense guide to Raspbian installation on a Pi 3.  It may be adaptable for Pi 4.

    https://github.com/IntelRealSense/librealsense/blob/master/doc/installation_raspbian.md#install-pyrealsense2 

    My understanding is that using CMake in the way described in that link installs only the Pyrealsense2 wrapper, as it assumes that librealsense is already installed.

    If that does not work, I recommend opening a new case about it on the GitHub forum.  I'm sorry again for your difficulties.

    2
    Comment actions Permalink
  • Cnorton

    Thanks MartyG, with that guide I got the realsense viewer to work!

    However, I am still getting a ModuleNotFoundError for pyrealsense2 when I run my code. Tried running one of the example python scripts and got that error and it was even inside the new libsense folder that I cloned from the guide.

    0
    Comment actions Permalink
  • MartyG

    If setting the PYTHONPATH is not working for you on Raspbian, an alternative for Ubuntu users is to copy the files librealsense2.so and pyrealsense2.so into the same folder where your Python example script is located.  I would hope that the same would be true for Raspbian, which I believe is related to Debian Linux.  I am not certain though to be honest.

    Bear in mind that if you are using Python 3, the pyrealsense2.so file will have a weird extended name like pyrealsense2.cpython-35m-arm-linux-gnueabihf.so

    0
    Comment actions Permalink
  • Cnorton

    I found librealsense2.so and added it to the examples folder. However I cannot find the pyrealsense2.so or pyrealsense2.cpython-35m-arm-linux-gnueabihf.so

    Am I able to find these files elsewhere? because they are not in the libsense repo.

    0
    Comment actions Permalink
  • MartyG

    My recollection is that when the Python bindings are built, a pyrealsense2 folder is created in the build folder of librealsense.  Can you find pyrealsense2.so by doing a file search for this filename with the file search tool of the folder window whilst in the Pyrealsense2 root folder?

    0
    Comment actions Permalink
  • Cnorton

    I still cannot find the pyrealsense2.so. I searched pyrealsense2 throughout the entire computer and got one folder that was in the libsense root folder and all it had was a init.py in it. I don't think there is a pyrealsense.so file anywhere on my computer.

    0
    Comment actions Permalink
  • Cnorton

    I found pyrealsense2.cpython-34m.so under build/wrapper/python (not sure why it didn't show up in my search). I put it into the examples folder where I ran the script and still have the same error.

    0
    Comment actions Permalink
  • MartyG

    I believe that a script that simply contains import pyrealsense2 as rs and nothing else is enough to test whether the Pyrealsense2 module can be found.  Put the script in the build > Pyrealsense2 folder and put the two .so files in the Pyrealsense2 folder too.  

    0
    Comment actions Permalink
  • Cnorton

    There is no pyrealsense2 folder in the build folder, but I went ahead and made a pyrealsense2 folder anyways to try and added both so files. I made a python file with just import pyrealsense2 as rs and got the same error.

    0
    Comment actions Permalink
  • MartyG

    When you got the RealSense Viewer to work using Intel's Raspbian guide, can you confirm that you changed to the librealsense build folder and installed Pyrealsense2 with the Pyrealsense2 section of the guide, please?

    https://github.com/IntelRealSense/librealsense/blob/master/doc/installation_raspbian.md#install-pyrealsense2 

    0
    Comment actions Permalink
  • Cnorton

    Ran it again, should I be seeing a pyrealsense2 folder? Cause I'm not seeing that.

    0
    Comment actions Permalink
  • MartyG

    I have no experience of using Raspbian, so I do not know what the outcome of the installation should look like, unfortunately.  I checked some further references.  Apparently the folder structure is librealsense > build > wrappersPython.  I do apologise.

    According to the experiences of Pi 4 users who tried to set up Pyrealsense2, putting the two .so files into any folder alongside your Python script should be sufficient.

    One user had success by editing the CMakeLists.txt file.

    https://github.com/IntelRealSense/librealsense/issues/4375#issuecomment-509968417 

    This subject goes beyond my current knowledge though.  If you do not get it working with the guidance in that link then I recommend opening a help case on the RealSense GitHub so Raspbian experts can provide assistance.  Sorry I could not be of more help in this particular case.

    1
    Comment actions Permalink
  • Cnorton

    I literally don't know what I did differently, but it all of the sudden started working for me! Thank you for your help! I was one command away from giving up, I even got ubuntu mate ready to flash onto another SD card before I tried it again and it worked!

    0
    Comment actions Permalink
  • MartyG

    Great news!  Yes, sometimes there are cases where you 'do something' and it finally works, but you never know why.  These cases are certainly a learning experience though.  Congratulations!

    0
    Comment actions Permalink
  • Shane Huston

    I have tried everything mentioned in this thread except editing my CMAKELISTS.txt file. The realsense-viewer works, but I can't get pyrealsense2 to install it seems. Inside my build/wrappers directory, there is no python folder, so I don't have the pyrealsense2.co file either. I tried the steps for installing pyrealsense2 from the Pi 3 instructions, but still no luck. I'm using a Pi 4 4GB and I started from the MicroSD img that Intel provides here:
    https://dev.intelrealsense.com/docs/open-source-ethernet-networking-for-intel-realsense-depth-cameras#section-2-3-preparing-the-sd-card

    MartyG or Cnorton do either of you have any suggestions?

    0
    Comment actions Permalink
  • MartyG

    Shane Huston  Editing the cmakelists.txt file is the solution given by most RealSense Pi 4 users for getting librealsense building working on Pi 4 and Raspbian Buster.

    https://github.com/IntelRealSense/librealsense/issues/4375#issuecomment-509968417 

    0
    Comment actions Permalink
  • Cnorton

    It seems like the pyrealsense.so file is what fixed the problem I had, but I was also trying a lot of things so I don't actually know what fixed the issue. I can send you my MicroSD image if that would be helpful.

    0
    Comment actions Permalink
  • Shane Huston

    I tried editing the /wrappers/python/CMakeLists.txt file as described above, and I noticed the make -j1 task took much longer so I was hopeful, but I still don't have anything in my build/wrappers folder other than some CMake stuff after doing the sudo make install.

    Cnorton That would be great. If you don't want to post a link here, I can be emailed at my first name dot last name at gmail.com. Thanks very much!

    0
    Comment actions Permalink
  • Cnorton

    Shane Huston. Sorry I've been trying the past 2 days to make an image and for some reason there some hardware errors. I plugged it back into the pi and it still works, but can't figure out how to make an image. I've tried with Win32 Disk Imager.

    0
    Comment actions Permalink

Please sign in to leave a comment.