Raspberry Pi ModuleNotFoundError: No module named 'pyrealsense2'
Hi,
I am having trouble importing pyrealsense2 on my raspberry pi. I got it successfully running on my windows laptop, but for some reason it's much harder on the raspberry pi. I have tried to pip (and pip3) install pyrealsense2, but I get the following error:
"ERROR: Could not find a version that satisfies the requirement pyrealsense2 (from versions: none)
ERROR: No matching distribution found for pyrealsense2"
I also tried building from source, but when I run make -j4 I run into issues with files missing like config.h (which I found) and libudev.h (which I did not find).
Has anyone had any luck running pyrealsense2 on raspbian?
-
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
-
Hi MartyG,
Looks like that built:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/Desktop/librealsense-master/librealsense-master/wrappershowever when I try running the python file I get the same error:
ModuleNotFoundError: No module named 'pyrealsense2'
-
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 2There 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).
-
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 2When I do a directory search, there's like 8 different config files. Which one am I looking for?
-
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/libI 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? -
I hope that the guide in the link below will help you to overcome the module not found error on Raspbian.
-
The link below is Intel's own librealsense guide to Raspbian installation on a Pi 3. It may be adaptable for Pi 4.
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.
-
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.
-
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
-
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?
-
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?
-
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 > wrappers > Python. 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.
-
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 -
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
-
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!
Please sign in to leave a comment.
Comments
51 comments