I couldn't import librealsense2
I have a Jetson Nano and I tried to use pyrealsense2 library via building from source. I couldn't get any error during installation but i got "no module named pyrealsense2.pyrealsense2" error. Also i added the .so files into the same folder with the python script that i run
this script from librealsense github:
jetpack: 4.4
ubuntu: 18.04
python 3.10.0
-
Hi Abdullaherzin80 It is rare that the pyrealsense2.pyrealsense2 instruction is used. It is more common to use import pyrealsense2 as rs
Does the script work if you only have one pyrealsense2 in your import instruction?
-
I already used import pyrealsense2 as rs in in the python file. The error caused because of the __init__.py at the /usr/local/lib/python3.10/pyrealsense2 location. I saw some suggestion at realsense github issues, so i copy the __init__ file into the that directory. If i remove the __init__ file from /usr/local/lib/python3.10/pyrealsense2, I got error like "Attribute error: module 'pyrealsense2' has no attribute 'pipeline' at ths line:
pipeline = rs.pipeline()
there is no error while importing pyrealsense2 like import pyrealsense2 as rs but i can't use any of the pyrealsense function, even this:
print(rs.__version__) -
If you are using a Linux computer then the two .so files to copy to the same folder as your project script are librealsense2.so and pyrealsense2.so. If the folder image above is from your Jetson Nano then I can see a librealsense2.so file in the folder but not pyrealsense2.so.
Building the pyrealsense2 wrapper for Python 3.10 from source code is fine, and your JetPack 4.4 version is compatible with the RealSense SDK.
-
It has been a year since I left this comment on github https://github.com/IntelRealSense/librealsense/issues/11506#issuecomment-1599168850 .
Then, I moved the pyrealsense2* .so files to $HOME. I tried moving these to `dist-packages/pyrealsense` within Ubuntu 24.04 on RPI, but I had the same error as the OP. For me, it was natural to expect these `.so` files to be in their `dist-packages`. It works if I explicitly specify the package path in python script with `sys.path.insert(0, '/usr/local/lib/python3.12/dist-packages/pyrealsense')`. Of course, it also works if the pyrealsense2* .so files are either in $HOME or working directory.
Do you have any idea about this ?
-
Your package path method seems to be equivalent to the RealSense Python wrapper's method of setting the path to '/usr/local/lib where Python 3 can be found by setting a PYTHONPATH variable. So I can understand why your approach would work too.
The wrapper's alternative to setting a path with the PYTHONPATH variable is to place the .so files in the same folder that your pyrealsense2 program script is located in.
Please sign in to leave a comment.
Comments
9 comments