View my account

I couldn't import librealsense2

Comments

9 comments

  • Abdullaherzin80

    I'm sorry I forgot to say i have a D405 camera

    0
    Comment actions Permalink
  • MartyG

    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?

    0
    Comment actions Permalink
  • Abdullaherzin80

    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__)

    0
    Comment actions Permalink
  • MartyG

    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.

    0
    Comment actions Permalink
  • Stakoverflowed

    MartyG

    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 ?

    0
    Comment actions Permalink
  • MartyG

    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.

    0
    Comment actions Permalink
  • Stakoverflowed

    Marty, I agree but I had to manually put the pyrealsense*.so files in appropriate location ($HOME or working dir). This was the case a year ago and even now, is this by design ? Or should it be taken care by the `sudo make install` command ?

    0
    Comment actions Permalink
  • MartyG

    I researched your strategy of moving the .so files to $HOME.  It looks as though you are the only RealSense user who is using this method with pyrealsense2 installation though, so I do not have advice to offer about this unfortunately.  I do apologize.

    0
    Comment actions Permalink
  • Stakoverflowed

    Marty,

    No problem. The reason I put the pylibrealsense.so file in the $HOME is to ensure that all other python packages can see it.

    0
    Comment actions Permalink

Please sign in to leave a comment.