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

Not able to use pyrealsense2. "No Module named pyrealsense2" #12377

Closed
ta-jetson opened this issue Nov 8, 2023 · 6 comments
Closed

Not able to use pyrealsense2. "No Module named pyrealsense2" #12377

ta-jetson opened this issue Nov 8, 2023 · 6 comments

Comments

@ta-jetson
Copy link

@MartyG-RealSense

| Required Info
|---------------------------------|------------------------------------------- |
| Camera Model - D435i
| Firmware Version - 05.15.01.00
| Operating System & Version - Ubuntu 18|
| Release- 4.9.201 - tegra
| Jetpack - 4.5.1
| OpenCV - 3.4.3 with CUDA : YES
| Platform - Nvidia Jetson (Seed studio cariier)
| SDK Version- 2.48.0
| Realsense-ros - 2.3.1

Issue Description

I built librealsense according to the issue "RealSense SDK & pyrealsense2 Installation on Nvidia Jetson Modules #10891" . I used selim35's bash file.
In the DPYTHON_EXECUTABLE, i have used /usr/bin/python and /usr/bin/python3 (as well as python2.7 and python3.6). The build was completed successfully every time. I even got the .so files for pyrealsense2 as well.
I still can't import pyrealsense2 in both approaches. I tried
import pyrealsense2 as rs
as well as
import pyrealsense2.pyrealsense2 as rs
Both give the "Module not found error"

and
I noticed
"/usr/local/lib/python2.7/" or "/usr/local/lib/python3.6/" doesn't have pyrealsense2

Could you please suggest how I could proceed?

NOTE - I used libsense 2.48.0 and JP- 4.5.1 as in one of the issues this was suggested as a fix for the imu data which isn't received in the lastest version. (Tested)

I had another question
I plan on using the IR cameras through the ros wrapper for VIO and pyrealsense2 to access the rgb camera for detection. Would it be possible to use it simultaneously ?

@ta-jetson ta-jetson changed the title Not able to pyrealsense2. "Module not found" Not able to use pyrealsense2. "Module not found" Nov 8, 2023
@ta-jetson ta-jetson changed the title Not able to use pyrealsense2. "Module not found" Not able to use pyrealsense2. "No Module named pyrealsense2" Nov 8, 2023
@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Nov 8, 2023

Hi @ta-jetson If you have the .so files then an alternative to using a Python path to connect Python and pyrealsense2 together is to place the .so files librealsense2.so and pyrealsense2.so in the same folder that your project script is in.

If you are using Python 2.7 then place pyrealsense2.so in the project folder.

If using Python 3.6 then the pyrealsense2.so file that should be placed in the project folder is the one that will have a more complex auto-generated filename, such as pyrealsense2.cpython-36m-arm-linux-gnueabihf.so (one that starts with 'pyrealsense2' and ends with '.so').

The number in the middle of the filename, such as '36m', refers to the Python 3 version that you have got installed on your computer. 36m stands for Python 3.6.


Almost all of your system configuration listed at the top of this case looks correct. It is worth mentioning though that the recommended camera firmware driver version to use with librealsense 2.48.0 is 5.12.14.50. Using a newer firmware such as 5.15.1.0 with an older SDK version may result in errors, as 5.15.1.0 is designed for use with SDK 2.54.2.

@MartyG-RealSense
Copy link
Collaborator

In regard to using infrared and RGB simultaneously, yes you can as the D435i camera has its own dedicated RGB sensor separate from the IR sensors.

@ta-jetson
Copy link
Author

ta-jetson commented Nov 8, 2023

Thank you @MartyG-RealSense
Error was resolved.

But I can't run them simultaneously.
I have a python file which uses the rgb camera. Just viewing for now.
I have launch file in realsense-ros for the infra and imu topics.
When I run realsense-ros launch file and then the python file,

Traceback (most recent call last):
File "rs_py.py", line 39, in
pipeline.start(config)
RuntimeError: xioctl(VIDIOC_S_FMT) failed Last Error: Input/output error

When I run the python file, and then realsense-ros file,

[ERROR] [1699446990.264410758]: An exception has been thrown: xioctl(VIDIOC_S_FMT) failed Last Error: Input/output error
[ERROR] [1699446990.264631492]: Exception: xioctl(VIDIOC_S_FMT) failed Last Error: Input/output error
08/11 18:06:30,263 ERROR [547656499584] (types.h:310) xioctl(VIDIOC_S_FMT) failed Last Error: Input/output error

How do I resolve this?

@MartyG-RealSense
Copy link
Collaborator

The librealsense SDK operates under a set of rules called Multi-Streaming Model (see the link below) that determines how access to the sensors by more than one application is governed.

https://github.com/IntelRealSense/librealsense/blob/master/doc/rs400_support.md#multi-streaming-model

The first program to access a particular stream type places a 'claim' on it and prevents another application from accessing that stream until the claim is released by the first program (such as by disabling streaming). So if realsense-ros enables a stream first, a Python script that is subsequently launched would be unable to use that stream.

The reverse is also true if the Python script was run first and realsense-ros second - the Python script could use the stream but realsense-ros couldn't.


As you are only using RGB in the Python script, let's make sure that realsense-ros is not also publishing the RGB stream and locking its access. Please try adding enable_color:=false to your launch instruction. If enable_color is true inside the launch file then the launch instruction command will override it and set it to false.

@ta-jetson
Copy link
Author

ta-jetson commented Nov 9, 2023

Hey @MartyG-RealSense ,
All of your advice has worked flawlessly.
Thank for your help.

Just a review on what I did to resolve (with the help of your advice) :
Used : to build my SDK with pyrealsense2 according to " #10891 (comment)"

The only change being -DPYTHON_EXECUTABLE=/usr/bin/python3.6

After that having the .so files in the project folder solved the "Module not found error problem".
To make sure I could use it anywhere, I used the following commands in the terminal(credit to ysozkaya/RealSense-Jetson#1 (comment))

In terminal :

sudo mkdir /usr/local/lib/python3.6/pyrealsense2

sudo ln -s ~/librealsense/build/wrappers/python/pybackend2.cpython-36-aarch64-linux-gnu.so /usr/local/lib/python3.6/pyrealsense2/

sudo ln -s ~/librealsense/build/wrappers/python/pyrealsense2.cpython-36-aarch64-linux-gnu.so /usr/local/lib/python3.6/pyrealsense2/

And I sourced my bashrc again. (Remember to make the changes in the bashrc according to " #10891 (comment)"

Now, import pyrealsense2 works without the need of adding the .so files in your project folder.

Using both the python and ros wrapper simultaneously issue was resolved by setting enable_color :=false.

Thanks a lot again @MartyG-RealSense

P.S :
I also performed the same build on Xavier NX.
libsense - 2.54

The only changes were python3.6 to python3.8. That is,
DPYTHON_EXECUTABLE=/usr/bin/python3.8

In .bashrc :

PYTHONPATH="/usr/local/lib:/usr/local/lib/python3.8/pyrealsense2:$PYTHONPATH"
export PYTHONPATH

In terminal :

sudo mkdir /usr/local/lib/python3.8/pyrealsense2

sudo ln -s ~/librealsense/build/wrappers/python/pybackend2.cpython-38-aarch64-linux-gnu.so /usr/local/lib/python3.8/pyrealsense2/

sudo ln -s ~/librealsense/build/wrappers/python/pyrealsense2.cpython-38-aarch64-linux-gnu.so /usr/local/lib/python3.8/pyrealsense2/

I'll be closing the issue.

@MartyG-RealSense
Copy link
Collaborator

You are very welcome. It's great to hear that you were successful. Thanks so much for sharing the details of your solution!

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

2 participants