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

No module named pyrealsense2 when using python wrapper #6449

Closed
miroslavradojevic opened this issue May 23, 2020 · 54 comments
Closed

No module named pyrealsense2 when using python wrapper #6449

miroslavradojevic opened this issue May 23, 2020 · 54 comments

Comments

@miroslavradojevic
Copy link

miroslavradojevic commented May 23, 2020

Required Info
Camera Model { D435i }
Firmware Version 05.12.03.00
Operating System & Version {Linux (Ubuntu 18.04)
Kernel Version (Linux Only) 5.3.0-53
Platform PC
SDK Version { 2.0 }
Language { python }
Segment { Robot }

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.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 23, 2020

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?

https://itsfoss.com/install-pip-ubuntu/

@miroslavradojevic
Copy link
Author

miroslavradojevic commented May 23, 2020

Yes, pip is installed on Ubuntu, it is the command I use very often. I have it paired with python3.
I switched to windows 10 where SDK is also installed and I get following error after trying to install pyrealsense2 package:

pip install pyrealsense2
ERROR: Could not find a version that satisfies the requirement pyrealsense2 (from versions: none)
ERROR: No matching distribution found for pyrealsense2

As a reference,

pip -V
pip 20.1.1 from c:\python38\lib\site-packages\pip (python 3.8)

Python 3.8 is installed in c:\python38

I could not get the python wrapper library on windows 10 either. SDK is installed in
C:\Program Files (x86)\Intel RealSense SDK 2.0
I can see the libraries (pyrealsense2.pyd, pyrealsense.dll) in:
C:\Program Files (x86)\Intel RealSense SDK 2.0\bin\x64
Should I maybe add \bin\x64\ folder to the PATH?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 23, 2020

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.

#5777 (comment)

@miroslavradojevic
Copy link
Author

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.

@MartyG-RealSense
Copy link
Collaborator

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!

@miroslavradojevic
Copy link
Author

No worries, it is not urgent, would be great to clarify what happens in linux, but this will do it for now.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 24, 2020

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

@miroslavradojevic
Copy link
Author

miroslavradojevic commented May 28, 2020

Hello, I tried installing pyrealsense2 wrapper on Ubuntu 18.04 using command:
pip3 install pyrealsense2
Collecting pyrealsense2 Could not find a version that satisfies the requirement pyrealsense2 (from versions: )
No matching distribution found for pyrealsense2

Ubuntu 18.04 runs on Jetson Nano computer, and I did previously install SDK 2.0 (it is possible to call realsense-viewer).
Both pip (for python 2 and 3 ) are installed:

$ pip -V
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip3 -V
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

What I also noticed is that when istalling SDK 2.0, command:
sudo apt-get install librealsense2-dkms
failed
E: Unable to locate package librealsense2-dkms

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?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented May 28, 2020

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.

#6460 (comment)

Are you trying to install on a Pi with pip, please?

@miroslavradojevic
Copy link
Author

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.

@MartyG-RealSense
Copy link
Collaborator

@miroslavradojevic Great to know that you had a successful install on Ubuntu. Thanks for the update!

@GOBish
Copy link

GOBish commented Jun 28, 2020

I am using an nvidia xavier nx, and all of the following fail:
pip install pyrealsense2
pip3 install pyrealsense2

Collecting pyrealsense2 Could not find a version that satisfies the requirement pyrealsense2 (from versions: )
No matching distribution found for pyrealsense2

and
sudo apt-get install librealsense2-dkms
E: Unable to locate package librealsense2-dkms

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jun 28, 2020

@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.

@GOBish
Copy link

GOBish commented Jun 28, 2020

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?

@MartyG-RealSense
Copy link
Collaborator

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=...

@GOBish
Copy link

GOBish commented Jun 28, 2020

Thanks Marty.
I am also trying the flag --DBUILD_WITH_CUDA:bool=true but I get the error

-- Info: Building with CUDA requires CMake v3.8+
-- The CUDA compiler identification is unknown
CMake Error at CMake/cuda_config.cmake:3 (project):
  No CMAKE_CUDA_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CUDACXX" or the CMake cache entry CMAKE_CUDA_COMPILER to the full
  path to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
  CMake/global_config.cmake:65 (include)
  CMakeLists.txt:44 (global_set_flags)

cmake --version returns 3.10.12

@GOBish
Copy link

GOBish commented Jun 28, 2020

I think CUDA error is solved by adding this to bashrc:

# cuda 10.2
export CUDA_HOME=/usr/local/cuda-10.2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.2/lib64:/usr/local/cuda-10.2/extras/CUPTI/lib64
export PATH=$PATH:$CUDA_HOME/bin

@MartyG-RealSense
Copy link
Collaborator

@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:

#6573 (comment)

A proper fix has been merged into the SDK development.

#6581

@GOBish
Copy link

GOBish commented Jun 28, 2020

OK, I am still trying, I get the following error now:

$ cmake ../ -DBUILD_PYTHON_BINDINGS:bool=true -DFORCE_RSUSB_BACKEND=ON -DPYTHON_EXECUTABLE=... -DBUILD_WITH_CUDA:bool=true 
-- Internet connection identified
-- Info: REALSENSE_VERSION_STRING=2.35.2
-- Setting Unix configurations
-- Info: Building with CUDA requires CMake v3.8+
-- CUDA_LIBRARIES: /usr/local/cuda/include /usr/local/cuda/lib64/libcudart_static.a;-lpthread;dl;/usr/lib/aarch64-linux-gnu/librt.so;/usr/local/cuda/lib64/libcusparse.so;/usr/lib/aarch64-linux-gnu/libcublas.so
-- using RS2_USE_LIBUVC_BACKEND
CMake Error at wrappers/python/third_party/pybind11/tools/FindPythonLibsNew.cmake:95 (message):
  Python config failure:

Call Stack (most recent call first):
  wrappers/python/third_party/pybind11/tools/pybind11Tools.cmake:16 (find_package)
  wrappers/python/third_party/pybind11/CMakeLists.txt:33 (include)


-- Configuring incomplete, errors occurred!

@MartyG-RealSense
Copy link
Collaborator

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.

@GOBish
Copy link

GOBish commented Jun 28, 2020

taking that line out or using -DPYTHON_EXECUTABLE=/usr/bin/python makes the build complete successfully.

@MartyG-RealSense
Copy link
Collaborator

@GOBish Great news!

@GOBish
Copy link

GOBish commented Jun 28, 2020

Thank you very much for the excellent and quick help!

@GOBish
Copy link

GOBish commented Jul 14, 2020

Just as an update, with the new version of the SDK 2.36.0 (released July 9,2020), the PYTHONPATH must now be
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/pyrealsense2

@GOBish
Copy link

GOBish commented Jul 14, 2020

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)
Has anyone been able to get it to work with python 3?

@GOBish
Copy link

GOBish commented Jul 15, 2020

yes, always completed the whole process, no change.

@MartyG-RealSense
Copy link
Collaborator

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.

@GOBish
Copy link

GOBish commented Jul 15, 2020

yes, I check the folder every time. No apologies needed, I have for sure overlooked the basics plenty of times in the past.

@MartyG-RealSense
Copy link
Collaborator

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

@GOBish
Copy link

GOBish commented Jul 15, 2020

python2 and python3 is installed with the disk image for the xavier jetpack 4.4

@MartyG-RealSense
Copy link
Collaborator

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

@GOBish
Copy link

GOBish commented Jul 15, 2020

"python3-dev is already the newest version"

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jul 15, 2020

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.

@GOBish
Copy link

GOBish commented Jul 15, 2020

ok, thanks for trying. I'll keep at it and update with any results I can achieve.

@MartyG-RealSense
Copy link
Collaborator

I appreciate your patience. I'm sorry I couldn't be of more help.

@GOBish
Copy link

GOBish commented Jul 16, 2020

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

@GOBish
Copy link

GOBish commented Jul 26, 2020

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:

Install the project...
-- Install configuration: ""

.
.
.
-- Up-to-date: /usr/local/lib/python2.7/pyrealsense2/pybackend2.so.2.36.0
-- Up-to-date: /usr/local/lib/python2.7/pyrealsense2/pybackend2.so.2
-- Up-to-date: /usr/local/lib/python2.7/pyrealsense2/pybackend2.so
-- Up-to-date: /usr/local/lib/python2.7/pyrealsense2/pyrealsense2.so.2.36.0
-- Up-to-date: /usr/local/lib/python2.7/pyrealsense2/pyrealsense2.so.2.36
-- Up-to-date: /usr/local/lib/python2.7/pyrealsense2/pyrealsense2.so
 

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jul 26, 2020

@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.

#6922 (comment)

@GOBish
Copy link

GOBish commented Jul 26, 2020

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

@MartyG-RealSense
Copy link
Collaborator

@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.

#2431 (comment)

@GOBish
Copy link

GOBish commented Jul 26, 2020

yeah, super frustrating because I have some other programs that only run with python 3 and I need to integrate realsense into those projects.

@MartyG-RealSense
Copy link
Collaborator

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?

@GOBish
Copy link

GOBish commented Jul 26, 2020

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.

@MartyG-RealSense
Copy link
Collaborator

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.

@GOBish
Copy link

GOBish commented Jul 31, 2020

Hi @MartyG-RealSense - I was finally able to solve this. See issue #6980 .

@MartyG-RealSense
Copy link
Collaborator

@GOBish Awesome, thanks for the update on your success!

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

3 participants