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

Realsense with Python3 #20

Closed
far-command-man opened this issue Mar 2, 2020 · 15 comments
Closed

Realsense with Python3 #20

far-command-man opened this issue Mar 2, 2020 · 15 comments

Comments

@far-command-man
Copy link

Hi @srware ,
After your last commit, it is now possible to use T265/D435 with C++ code properly. However, I recently ran into a new issue. I follow the instructions given in README to add Python3 support in my image. I can import pyrealsense2 without any issue but it runs into an error once I declare RealSense sensor pipeline such as pipe = rs.pipeline(). It says AttributeError: module 'pyrealsense2' has no attribute 'pipeline'.
I saw this issue IntelRealSense/librealsense#4483 (comment) . The error messages we have looks the same but I am not sure how to resolve it in Yocto. Any help from your side is much appreciated.

@srware
Copy link
Collaborator

srware commented Mar 2, 2020

Hi @far-command-man,

Thanks for flagging this. The problem is actually directory structure related. The python libs install to "/usr/lib/python3.x/site-packages/pyrealsense2" which isn't in the PYTHON_PATH. If the libs are moved up one level to "site-packages" everything works as expected.

I will get it fixed!

Thanks.

@far-command-man
Copy link
Author

@srware I checked out the "/usr/lib/python3.x/site-packages/pyrealsense2" and found pyrealsense shared object libraries there. I placed them under site-packages/ directory now everything works fine but of course the best way is to get them installed in respective directory originally. Thanks for the help! :)

@srware
Copy link
Collaborator

srware commented Mar 3, 2020

Should be fixed now.

Thanks.

@srware srware closed this as completed Mar 3, 2020
@tpwrules
Copy link

tpwrules commented Jul 16, 2020

I'm not sure this is the correct solution to the problem. Putting the shared libraries in site-packages can (although is unlikely to) interfere with other packages. The correct solution would be to copy the wrappers/python/pyrealsense2/__init__.py into the <etc>/site-packages/pyrealsense2 directory, along with the shared libraries. I'm not sure why that doesn't happen by default.

@persalteas
Copy link

persalteas commented Sep 4, 2020

Hi, thanks tpwrules, this worked.

After compiling librealsense (using cmake .. -DBUILD_PYTHON_BINDINGS:bool=true), i had the same issue when importing pyrealsense2 in python3.

However, your package is not necessarily in site-packages. You need to first identify where your pyrealsense2 is:
$ python3
>> import pyrealsense2 as rs
>> rs.__path__
['/usr/lib/python3/dist-packages/pyrealsense2']

Then copy the __init__.py file in your package's folder:

sudo cp ~/librealsense/wrappers/python/pyrealsense2/__init__.py /usr/lib/python3/dist-packages/pyrealsense2/ solved it for me.

EDIT: typo

@lorepieri8
Copy link

lorepieri8 commented Sep 16, 2020

@persalteas instructions worked for me, there is a typo in his last line though:

sudo cp ~/librealsense/wrappers/python/pyrealsense2/__init__.py /usr/lib/python3/dist-packages/pyrealsense2/

@prog96
Copy link

prog96 commented Nov 6, 2020

@persalteas
Hello! I did the following but this error appeared. Do you know how to solve it?

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

@persalteas
Copy link

Hi edwin,
it's not rs.path, it's rs.__path__, try again with the double underscores.

@prog96
Copy link

prog96 commented Nov 8, 2020

I did that with the double underscores. It's just that when I copied it here it disappeared.

@srware
Copy link
Collaborator

srware commented Nov 9, 2020

@edwin9610 , I just tried to replicate this building an image from 'master' but it worked fine for me. I am assuming the pyrealsense2 library is being found in the path given it doesn't fail at the import stage.

I have now incorporated the recommendations in this thread into the master branch so maybe give it another go.

Thanks.

@prog96
Copy link

prog96 commented Nov 26, 2020

@srware Hi, sorry for the late reply.

I have these directories to the path.

jetson@jetson-desktop:~$ python -c "import sys; print(sys.path)"
['', '/home/jetson', '/usr/local/lib', '/usr/local/lib/python3.6/pyrealsense2', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-aarch64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/gtk-2.0']

as shown in the following screenshots.

screenshot
screenshot_1

But I still have the problem with this:
rs.path
Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'pyrealsense2' has no attribute 'path'

What should I do now?

@punchnami
Copy link

I'm getting the same error as @edwin9610 , is there any solution?

Thank you in advance!

@persalteas
Copy link

persalteas commented Jan 5, 2021

In @edwin9610 's case, since the __init__.py file is present in the pyrealsense2 folder, i think the problem is that /usr/local/lib/python3.6 is not in the path (the list you provided).

@punchnami do you have the package installed somewhere ? Check that the folder contains that __init__.py file (or copy it as i indicated earlier). If yes, check that your package folder is in Python's path.

@punchnami
Copy link

In @edwin9610 's case, since the __init__.py file is present in the pyrealsense2 folder, i think the problem is that /usr/local/lib/python3.6 is not in the path (the list you provided).

@punchnami do you have the package installed somewhere ? Check that the folder contains that __init__.py file (or copy it as i indicated earlier). If yes, check that your package folder is in Python's path.

Thank you @persalteas , I will check it out!

@christianschmitzuni
Copy link

After "sudo cp ~/librealsense/wrappers/python/pyrealsense2/init.py /usr/lib/python3.6/dist-packages/pyrealsense2/" and then copying the additional 6 .so files into /usr/lib/python3.6/dist-packages/pyrealsense2/ aswell

When using import pyrealsense2 I still get the following error:

import pyrealsense2
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.6/dist-packages/pyrealsense2/init.py", line 2, in
from .pyrealsense2 import *
ModuleNotFoundError: No module named 'pyrealsense2.pyrealsense2'

Anything that I am missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants