-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
No module named pyrealsense2 when using python wrapper #6449
Comments
Hi @miroslavradojevic I recently installed Pyrealsense2 with Python 3.7 on Windows and wrote my own manual for the process. I have not done it on Linux but will try to provide some useful guidance. Firstly, do you have the pip package management system installed in Ubuntu please? |
Yes, pip is installed on Ubuntu, it is the command I use very often. I have it paired with python3.
As a reference,
Python 3.8 is installed in c:\python38 I could not get the python wrapper library on windows 10 either. SDK is installed in |
PyPi installation of the Pyrealsense2 wrapper is supported up to Python 3.7 currently. Python 3.8 users should use 3.7 to install via pip or compile the Pyrealsense2 wrapper from source. |
Thanks for the help, reverting Python to 3.7.6 worked. I will double check which version it was in Ubuntu, wrapper seems to be running in windows 10. |
I'm very glad you found a version that worked for you! I'm off shift for the day now as it is almost midnight in my time zone. If you need further assistance, I will pick up new comments when I return in 7 hours from the time of writing this and be happy to continue the support conversation. Good luck! |
No worries, it is not urgent, would be great to clarify what happens in linux, but this will do it for now. |
I'm back. Thanks for your patience. The pip setup guide I linked to earlier suggests that Ubuntu 18.04 users install both pip for Python 2 and pip3 for Python 3, even if you are only using Python 3. I checked various sources of information about the next step of the pyrealsense2 installation process for Python 3. They suggested using the pip3 instruction below, having installed pip3 earlier: pip3 install pyrealsense2 |
Hello, I tried installing pyrealsense2 wrapper on Ubuntu 18.04 using command: Ubuntu 18.04 runs on Jetson Nano computer, and I did previously install SDK 2.0 (it is possible to call realsense-viewer).
What I also noticed is that when istalling SDK 2.0, command: It is till not possible for me to get the wrapper running on Ubuntu - and I need it running there because of the hardware. Would you be able to figure out why this happens? |
On another case this week, involving an attempt to use pip on Raspberry Pi, the RealSense SDK Manager said that pip would not work on Pi because it has an Arm processor and there is not a suitable package for it. Are you trying to install on a Pi with pip, please? |
I can confirm that the installation of the SDK 2.0 went fine on Ubuntu 18.04, and the wrapper is also installed and functional which should conclude this thread. |
@miroslavradojevic Great to know that you had a successful install on Ubuntu. Thanks for the update! |
I am using an nvidia xavier nx, and all of the following fail:
and |
@GOBish pip install will not work with Jetson devices unfortunately as they use Arm processors, which are incompatible with the pyrealsense2 pip packages. Jetson users should build the pyrealsense2 wrapper from source. |
Understood, thanks for the reply. I built from the Linux installation page using sudo apt-get and I was under the impression that that process should set up the wrappers and examples, and not need to be built further. Am I wrong? |
The PyPi pip packages are separate from the main SDK files and are built for x86 (32-bit) and x64 (64-bit) processors. Arm processors are not 'x' architecture. If you are building Librealsense from source with CMake then you can build the Pyrealsense2 wrapper at the same time by including -DBUILD_PYTHON_BINDINGS:bool=true in your CMake build statement. An Xavier user recently succeeded in building the Pyrealsense2 wrapper with this statement: -DBUILD_PYTHON_BINDINGS:bool=true -DFORCE_RSUSB_BACKEND=ON -DPYTHON_EXECUTABLE=... |
Thanks Marty.
cmake --version returns 3.10.12 |
I think CUDA error is solved by adding this to bashrc:
|
@GOBish If you are using the latest 2.35.2 SDK, it has a bug in it where Librealsense does not build if CUDA is set to True when building for Jetson. A fix for this is in the link below: A proper fix has been merged into the SDK development. |
OK, I am still trying, I get the following error now:
|
Does it make any difference if you leave out -DPYTHON_EXECUTABLE=... I have not personally seen this flag used in pyrealsense2 building with CMake before that particular Xavier case. |
taking that line out or using -DPYTHON_EXECUTABLE=/usr/bin/python makes the build complete successfully. |
@GOBish Great news! |
Thank you very much for the excellent and quick help! |
Just as an update, with the new version of the SDK 2.36.0 (released July 9,2020), the PYTHONPATH must now be |
Also, I have never been able to get the library to work with python3. The files never get created in the python3 folder even if I specify -DPYTHON_EXECUTABLE=/usr/bin/python3 (which is what "which python3" points to). Using -DPYTHON_EXECUTABLE=/usr/bin/python always creates the python libraries in the correct python 2 folder (which I point to in the post above is now different) |
yes, always completed the whole process, no change. |
Apologies for asking this, but are you certain that pyrealsense2 has not been built in the Python 3.6 folder. It would naturally already be in the Python 2.7 folder because you have already built pyrealsense2 for that Python version. |
yes, I check the folder every time. No apologies needed, I have for sure overlooked the basics plenty of times in the past. |
I have been through the case thoroughly and cannot see anything obviously wrong with how you have done things. As suggested by the wrapper instructions, did you install Python 3 using this method: sudo apt-get install python3-dev |
python2 and python3 is installed with the disk image for the xavier jetpack 4.4 |
Yes, I thought that it would be. I just wondered whether there was something in the pre-installed version of Python 3 that might be incompatible, compared with the one installed with sudo apt-get install python3-dev |
"python3-dev is already the newest version" |
I think every possibility has already been covered for getting Python 3 pyrealsense2 working using building from source. I do not know of anything else to try, unfortunately. It should be possible, but in this case it is not working. |
ok, thanks for trying. I'll keep at it and update with any results I can achieve. |
I appreciate your patience. I'm sorry I couldn't be of more help. |
I tried "make clean" and then did the full build again using DPYTHON_EXECUTABLE=/usr/bin/python3.6, and DPYTHON_EXECUTABLE=/usr/bin/python3 ,no change |
Can you think of any way to change the config? When I do sudo make install after specifying the python3.6 folder, the output still shows:
|
@GOBish I was working on another Pyrealsense2 installation case today that was successful in the end. The RealSense user in that case posted their own method that worked for them. |
Thanks, Marty - I saw that thread and I think that case seems different than mine. Building from source worked for him or her, as it did for me, but then he or she just had to take care of a PYTHONPATH issue. I looked at the cmake_install.cmake file in the librealsense/build/wrappers/python folder and all of the install directories there are set to /lib/python2.7/pyrealsense.... I tried manually changing those to python3.6, and while it did change the install location of the libraries to the right place, python3 could still not import pyrealsense2, still giving the error undefined symbol _Py_ZeroStruct |
@GOBish I am not certain why you are having so much difficulty with the install path on your Xavier NX when installing the wrapper from source. You have probably seen the Xavier pyrealsense2 case below, but I will link to it just in case you haven't. |
yeah, super frustrating because I have some other programs that only run with python 3 and I need to integrate realsense into those projects. |
Is there any possibility of uninstalling Python 2.7 and so preventing Pyrealsense2 from being installed to it, leaving Python 3 as the only choice? |
just removed all python2 and dependencies and it still installed it into a python2.7 folder. When I try to import in python3 still get the same error as before. |
At this point it may be best to start a new case of your own and describe your problem so that someone else can look at it with a fresh perspective. I can only think that there is something already installed on the NX that is causing a conflict with installation, since pyrealsense2 is only supposed to use Python 2 if it is not possible to use Python 3. |
Hi @MartyG-RealSense - I was finally able to solve this. See issue #6980 . |
@GOBish Awesome, thanks for the update on your success! |
Issue Description
I am trying to work with Realsense D435i camera on Ubuntu 18.04, using python wrapper. Upon calling
import pyrealsense2 as rs
in the script, I get error message: ImportError: No module named pyrealsense2
I have installed SDK 2.0 following the guidelines, SDK is installed using packages (it was not built from source).
Also I called
pip install pyrealsense2
as stated in the Installation
Can anyone provide any hints why the import is not working? I did scan previous similar issues on PC/RaspberryPIs and assumed it would not be necessary to build SDK from source. According to the documentation, calling
pip install pyrealsense2
should be sufficient.The text was updated successfully, but these errors were encountered: