Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running pyrealsense2 on JetsonNano #6964

Closed
fredy1221 opened this issue Jul 29, 2020 · 48 comments
Closed

Running pyrealsense2 on JetsonNano #6964

fredy1221 opened this issue Jul 29, 2020 · 48 comments

Comments

@fredy1221
Copy link

|---------------------------------|------------------------------------------- |
| Camera Model | D435i |
| Firmware Version | |
| Operating System & Version | Linux Ubuntu 18 LTS |
| Platform | NVIDIA Jetson Nano |
| Realsense SDK Version | legacy 2.36.0 |
| Language | python |
| Segment | Industrial robot |

Issue Description

I'm using Intel Realsense D435i connected to a NVIDIA Jetson Nano.
The Jetson is flashed with Jetpack 4.3

First I installed RealSense viewer and it worked fine, I was able to stream from the camera in both depth and RGB.
Then I installed a pyrealsense2 python wrapper so I can start a pipeline to get a frame using a python script, now I can successfully import pyrealsense2 in my script but the device is no longer detected.

running: $ rs-enumerate-devices
returns: No device detected. Is it plugged in?
Even though the camera is plugged in

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jul 29, 2020

Hi @fredy1221 The pyrealsense2 wrapper cannot be installed with the pip install pyrealsense2 method on devices with Arm processors such as Jetson, because the PyPi pip packages are not compatible with Arm processors.. That typically means that the best option is to use CMake to build librealsense and the Python bindings at the same time.

The first step in this process is to download the source code of librealsense from the Releases page as a zip file. The source code zip file can always be found in the "Assets" list at the bottom of the information listing for each SDK version on the Releases page.

https://github.com/IntelRealSense/librealsense/releases/

image

After downloading the zip file, its contents should be extracted so that you have a librealsense folder.At this point you can use the RSUSB installation method to install librealsense without dependence on Linux versions or kernel versions and without the need for patching. This makes this installation method particularly suited to Arm devices such as Jetson.

The backend installation method requires an internet connection. The steps are:

  1. Go to the librealsense root directory. Create a folder within it called build and then go to this new folder using this instruction:

mkdir build && cd build

  1. Now that you are in the build directory, run the CMake build instruction below to install librealsense and the Python bindings over the internet connection:

cmake ../ -DFORCE_RSUSB_BACKEND=ON -DBUILD_PYTHON_BINDINGS:bool=true -DPYTHON_EXECUTABLE=...

The above statement is a basic one that should test whether the build is likely to succeed or not. If it does succeed then you can try a more advanced build, which builds the example programs and includes optimizations such as building with CUDA support for faster alignment processing on devices such as Jetson that are equipped with an Nvidia graphics GPU.

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

@fredy1221
Copy link
Author

Thank you for your help, it worked!

@MartyG-RealSense
Copy link
Collaborator

Excellent news - thank you very much for the update! :)

@ramgrandhi
Copy link

ramgrandhi commented Aug 1, 2020

Hello @MartyG-RealSense - Thanks for your inputs so far! On a fresh install of JetPack 4.4 with Python3.7 as default (python3), I ran into this issue while installing basic command you provided.

xxx@yyy:/librealsense-2.36.0/build$ **sudo cmake ../ -DFORCE_RSUSB_BACKEND=ON -DBUILD_PYTHON_BINDINGS:bool=true -DPYTHON_EXECUTABLE=/usr/bin/python3**
-- Internet connection identified
-- Info: REALSENSE_VERSION_STRING=2.36.0
-- Setting Unix configurations
-- Info: Building with CUDA requires CMake v3.8+
-- CUDA_LIBRARIES: /usr/local/cuda/include /usr/local/cuda/lib64/libcudart_static.a;dl;/usr/lib/aarch64-linux-gnu/librt.so;/usr/local/cuda/lib64/libcusparse.so;/usr/lib/aarch64-linux-gnu/libcublas.so
-- using RS2_USE_LIBUVC_BACKEND
-- pybind11 v2.2.1
-- GLFW 3.3 not found; using internal version
-- Could NOT find Vulkan (missing: VULKAN_LIBRARY VULKAN_INCLUDE_DIR) 
-- Using X11 for window creation
CMake Error at third-party/glfw/CMakeLists.txt:235 (message):
  **The Xinerama headers were not found**


-- Configuring incomplete, errors occurred!
See also "/librealsense-2.36.0/build/CMakeFiles/CMakeOutput.log".
See also "/librealsense-2.36.0/build/CMakeFiles/CMakeError.log".

UPDATE: I was able to resolve this issue by installing these two packages.

sudo apt-get install -y libxinerama-dev libxcursor-dev

Hope it helps someone looking for the complete answer!

cheers.

@MartyG-RealSense
Copy link
Collaborator

It's great that you quickly found a solution to your particular problem @ramgrandhi - thanks so much for sharing it!

@ramgrandhi
Copy link

You're welcome @MartyG-RealSense!

Though I can see pyrealsense2 packages installed, I still cannot import them from python3 REPL. Do you think I should explicitly create symlinks ?

xxx@yyy:/$ **find . -name pyrealsense2 2>/dev/null**
./librealsense-2.36.0/build/wrappers/python/CMakeFiles/Export/lib/cmake/pyrealsense2
./librealsense-2.36.0/wrappers/python/pyrealsense2

cheers!

@MartyG-RealSense
Copy link
Collaborator

@ramgrandhi If you think that you need symbolic links (most people do not use them with Pyrealsense2), this may be a useful reference:

#5275 (comment)

Otherwise you could try this:

#5275 (comment)

@birdistheword96
Copy link

birdistheword96 commented Oct 1, 2020

I am having the same issue, where I could originally see the stream from the camera but after installing pyrealsense2 wrapper it stopped working.

I followed @MartyG-RealSense 's instructions (which were great btw) and got all the way through without any errors. However, when i run 'realsense-viewer' from command line it opens v2.31.0, rather than the version I have just complied with make/cmake which is v2.38.1.

I think having v2.31.0 is the problem as my L515 is not detected by it, so when i run any example python scripts (from the new folder) or the realsesense-viewer then the camera is not detected...

I'm sure many other people will find themselves on this page after having issues installing realsense, and have probably (like me) tried other tutorials that have installed other versions deep within the filesystem.

So my question: is there any easy way to remove the old version and swap it with the new one? and how do I link it to the 'realsense-viewer' command which is presumably calling the app from a link in /usr/bin folder?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Oct 1, 2020

Hi @birdistheword96 Official support in the SDK for the L515 camera model began with version 2.35.2.

If you built from source code with CMake then the link below provides guidance about where to find the built binary of the Viewer within the folder structure of the 2.38.1 SDK version that you have just built.

#1980 (comment)

If you have 2.31.0 installed somewhere on your Jetson and you built it from source code, you could go to the build folder of that SDK and run this CMake command from that location:

sudo make uninstall && make clean

This should uninstall the SDK and clean up old files.

@birdistheword96
Copy link

@MartyG-RealSense again thank you for the uninstall suggestion, this seems to have worked because I can run the realsense-viewer from the command line (although it reports to be 2.35.2, despite being built from 2.38.1) and I can now see the camera feed.

I tried one of the python examples and it said it couldn't import the module pyrealsense2, I think i read somewhere that I have to ad it to the python path or copy a .so file into the folder, is that correct?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Oct 1, 2020

Hi @birdistheword96 Getting the Python wrapper working can depend on what term is used with DPYTHON_EXECUTABLE as this dictates how to find your Python installation. If you have Python 3 installed and making DPYTHON_EXECUTABLE = ... does not work, then a good starting point for testing is to use this term:

-DPYTHON_EXECUTABLE=/usr/bin/python3

@birdistheword96
Copy link

hi @MartyG-RealSense , initially the DPYTHON_EXECUTABLE = ... didnt work, so I tried -DPYTHON_EXECUTABLE=/usr/bin/python3 and that compiled successfully.

However, I am unable to import the library, so I assume I am doing something wrong? or do I need to add something to the python path, or put the library in the same folder thatthe python file is in?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Oct 1, 2020

Can you provide the error message that you get when you are unable to import pyrealsense2, please?

@birdistheword96
Copy link

Yeah sure, should have included it in the original message sorry:

user:~/librealsense-2.38.1/wrappers/python/examples$ python3 opencv_viewer_example.py

Traceback (most recent call last):
  File "opencv_viewer_example.py", line 8, in <module>
    import pyrealsense2 as rs
ModuleNotFoundError: No module named 'pyrealsense2'

I know that this error means it can't find the module to import, so I either need to add it to the python path or copy the library into the local folder where python file is. But which file is it that I need to copy specifically? or whoch directory shoudl i be adding to the python path and is there an easy way to do it?

Thanks for all your help so far @MartyG-RealSense!

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Oct 2, 2020

@birdistheword96 Reading back to your original comment on this case in #6964 (comment) I note that you are using the L515 model. Could you therefore create a new issue about your current problem with ModuleNotFoundError: No module named 'pyrealsense2' and mention L515 in the case title please, as somebody else on the RealSense team other than myself is responsible or handling L515-related cases. I do apologise.

@birdistheword96
Copy link

@MartyG-RealSense No problem, will do.

@Drkstr
Copy link

Drkstr commented Oct 11, 2020

@MartyG-RealSense Thank you very much for the instructions above.

Unfortunately, I am still having trouble importing pyrealsense2. Here are the steps I followed:

  1. Download the zip file from https://github.com/IntelRealSense/librealsense/releases/. I am using version 2.38.1

  2. Extract the file and create a dir called build and cd into it.
    My directory structure for the build dir is /home/rakshak/git_repo/librealsense-2.38.1/build

  3. Run the CMake command to test to see if the build will work. I used this command
    cmake ../ -DFORCE_RSUSB_BACKEND=ON -DBUILD_PYTHON_BINDINGS:bool=true -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_BUILD_TYPE=release -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true -DBUILD_WITH_CUDA:bool=true

  4. Still in the build dir. Run make -j4 and then sudo make install

  5. Addexport PYTHONPATH=$PYTHONPATH:/usr/local/lib to the end of my .bashrc and source it.

Now when I try to import it into python3, I get the following error.

rakshak@RakshakNano:~$ python3
Python 3.6.9 (default, Jul 17 2020, 12:50:27) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyrealsense2 as rs
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyrealsense2'

I can see the librealsense2* files in /usr/local/lib/

rakshak@RakshakNano:/usr/local/lib$ ls
cmake                librealsense2-gl.so         librealsense2.so.2.38    python3.6
libfw.a              librealsense2-gl.so.2.38    librealsense2.so.2.38.1
libglfw3.a           librealsense2-gl.so.2.38.1  pkgconfig
librealsense-file.a  librealsense2.so            python2.7

I have also tried rebooting the Nano, still no luck.

Let me know if you need any more information.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Oct 11, 2020

Hi @Drkstr Another RealSense user with a Jetson who had the No module named 'pyrealsense2 error solved it by putting the two lines below at the end of their bash file as the final two lines:

export PATH=$PATH:~/.local/bin
export PYTHONPATH=$PYTHONPATH:/usr/local/lib

You can also check that your PYTHONPATH is set to the correct location by the bash file by using the command below after the bash script has been run:

echo $PYTHONPATH

@Drkstr
Copy link

Drkstr commented Oct 11, 2020

@MartyG-RealSense Thanks for the reply

I have added the following to the end of my .bashrc file and sourced the file

export PATH=$PATH:~/.local/bin
export PYTHONPATH=$PYTHONPATH:/usr/local/lib

echo $PYTHONPATH returns the following

rakshak@RakshakNano:~$ echo $PYTHONPATH
:/usr/local/lib

Still not able to import pyrealsense2

Not sure what else to try at this point 😿

SamuelHackettLee referenced this issue in SamuelHackettLee/RoverVision May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests