IntelRealSense / librealsense

Intel® RealSense™ SDK
https://www.intelrealsense.com/
Apache License 2.0
7.64k stars 4.83k forks source link

Ubuntu 20 / python 3.8 support #8416

Closed ShettyHarapanahalli closed 3 years ago

ShettyHarapanahalli commented 3 years ago
librealsense 2.42.0 RELEASE
OS Linux
Name Intel RealSense D435I
Serial Number 844212071706
Firmware Version 05.12.11.00
Advanced Mode YES
Camera Locked YES
Usb Type Descriptor 3.2
Product Line D400
Asic Serial Number 904523050880
Firmware Update Id 904523050880

Please provide a description of the problem- I am trying to install the python wrapper with "pip3 install pyrealsense2" but it did not work, so tried to install with build with the cmake command "cmake ../ -DFORCE_RSUSB_BACKEND=true -DBUILD_PYTHON_BINDINGS=true -DCMAKE_BUILD_TYPE=release -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true" I get the below error -

/home/suman/sandbox/librealsense/build/third-party/libusb/libusb/core.c:23:10: fatal error: config.h: No such file or directory 23 | #include "config.h"

I did install the usblib but of no use -
sudo apt-get install libusb-1.0-0-dev

Can you please help me fix the same.

MartyG-RealSense commented 3 years ago

Hi @ShettyHarapanahalli If you are using Ubuntu 20 and experiencing the error /librealsense/build/third-party/libusb/libusb/core.c:23:10: fatal error: config.h: No such file or directory 23 | #include "config.h" then advice about a fix for it is provided in the link below:

https://github.com/IntelRealSense/librealsense/issues/6436#issuecomment-653942842

I see that you have already used the first step of the recommendations, involving installing sudo apt-get install libusb-1.0-0-dev. Does the rest of the guidance match up with what you have already tried, please?

ShettyHarapanahalli commented 3 years ago

Thanks for the link. I got a big list of warnings but installed it successfully.

ShettyHarapanahalli commented 3 years ago

Any help with this, please -

suman@SumanDL:~/sandbox/librealsense/build$ python3 Python 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import pyrealsense2 as rs pipeline = rs.pipeline() Traceback (most recent call last): File "", line 1, in AttributeError: module 'pyrealsense2' has no attribute 'pipeline'

MartyG-RealSense commented 3 years ago

Hi @ShettyHarapanahalli I usually see this error occur on Nvidia Jetson and Raspberry Pi computing boards. Are you using a Jetson or Pi board please?

ShettyHarapanahalli commented 3 years ago

This is on laptop, I have ubuntu 20 trying to use it with python3.8.

MartyG-RealSense commented 3 years ago

The pip package installation would not work because at the time of writing this, pip installation up to Python 3.7 only is supported (though Intel have been actively working on adding support for newer Python versions recently).

In the meantime, building the pyrealsense2 wrapper from source code with CMake like you have been doing is the best option for Python versions newer than 3.7.

Though you are using a laptop, there was a Jetson case involving AttributeError: module 'pyrealsense2' has no attribute 'pipeline' where the solution in that particular case was found to be to copy .so files to the same directory that the user's project script was in.

https://github.com/IntelRealSense/librealsense/issues/7078#issuecomment-672949007

This same approach of copying the .so files into the same directory as the user's project script also worked in another case involving Pi:

https://support.intelrealsense.com/hc/en-us/community/posts/360048396854/comments/360012486393

ShettyHarapanahalli commented 3 years ago

I see only one file getting generated for some reason. Can you please help me fix this -

Cmd line dump - build$ ls *.so librealsense2.so

MartyG-RealSense commented 3 years ago

Okay, first please copy librealsense2.so to the same folder that your project script is in. Then find your pyrealsense2.so file and copy this into the folder alongside your project script too.

When using Python 3, the pyrealsense2.so file will not be called exactly that but have an unusual name based on the version of Python that you are using (such as pyrealsense2.cpython-37m-arm-linux-gnueabihf.so or something complex like that).

I recall that when I was performing a pyrealsense2 installation, I found it by going to the parent folder of the Python installation (e.g Python37) and doing a file search from that folder location for the search term pyrealsense2.so. This search located where the strangely named version of the pyrealsense2.so file was on my computer so that I could copy it into the folder where my project script was.

ShettyHarapanahalli commented 3 years ago

added this in 1st line of the file- librealsense/CMake/opengl_config.cmake set(OpenGL_GL_PREFERENCE "GLVND")

Path of the file - librealsense/build//librealsense2.so librealsense/build/wrappers/python/pybackend2.cpython-38-x86_64-linux-gnu.so

But of no output get, I have copied the *.so file to the example folders and executed python3 align-depth2color.py. CMD line dump of the same is below -

suman@SumanDL:~/sandbox/librealsense/wrappers/python/examples$ ls *.so librealsense2.so pybackend2.cpython-38-x86_64-linux-gnu.so suman@SumanDL:~/sandbox/librealsense/wrappers/python/examples$ python3 align-depth2color.py Traceback (most recent call last): File "align-depth2color.py", line 16, in pipeline = rs.pipeline() AttributeError: module 'pyrealsense2' has no attribute 'pipeline' suman@SumanDL:~/sandbox/librealsense/wrappers/python/examples$

MartyG-RealSense commented 3 years ago

Regarding having copied pybackend2.cpython-38-x86_64-linux-gnu.so to beside your project script, i don't believe that this is the correct file. It should start with 'pyrealsense2' and end in '.so' like the pyrealsense2.cpython-37m-arm-linux-gnueabihf.so example file-name structure that I mentioned earlier.

If an installation has numerous problems that require multiple fixes to be applied then it is usually easier to go back to the beginning, start the process over again and try to find out what the problem with the previous installation may have been.

For example, in your build you are using CMake to build librealsense and the Python wrapper together from source code, using -DFORCE_RSUSB_BACKEND=true. In this build method, there is no kernel patching required.

A flag that is usually included in a CMake build statement that is building librealsense at the same time as building librealsense though is -DPYTHON_EXECUTABLE. This condition defines which Python installation on the computer should be targetted. Your CMake instruction at the start of this case does not include this flag. -DPYTHON_EXECUTABLE should be set to = the exact path where your Python 3.8 installation is located on your computer.