RealSense D435 SDK run under Python Anaconda environment
| Required Info | |
|---|---|
| Camera Model | D435 |
| Firmware Version | 05.08.15.00 |
| Operating System & Version | Windows 10 |
| Platform | PC |
| SDK Version | v2.10.4 |
| Language | Python v2.7 & v3.6 |
Issue Description
Is it possible to use Intel RealSense SDK Python wrappers under Python Anaconda environment? I already followed all instruction as stated on github here https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python
But i'm facing problem when i tried to run sample python project ("opencv_viewer_example.py) under my virtual anaconda environment as stated below:-
Traceback (most recent call last):
File "opencv_viewer_example.py", line 8, in
Do you have any idea about this problem?
Can you try compiling pyrealsense2 with anaconda as the target? In the cmake, point pybind11 at anaconda's python executable instead of the one provided on python.org
This is how I've compiled
cmake ../ -DBUILD_EXAMPLES=bool:true -DBUILD_PYTHON_BINDINGS=bool:true -DBUILD_CV_EXAMPLES=bool:true -DPYTHON_EXECUTABLE=/home/mikeyr/anaconda3/envs/ENVIRONMENT_NAME_HERE/bin/python3.6
If that doesn't work you can compile like normal and make a symlink to the library.
Example:
ln -s /home/mikeyr/librealsense/build/wrappers/python/pyrealsense2.cpython-36m-x86_64-linux-gnu.so /home/mikeyr/anaconda3/envs/ENVIRONMENT_NAME_HERE/lib/python3.6/site-packages/pyrealsense2.so
@lramati can you elaborate more details about pointing pybind11 at anaconda python executabe in cmake?
@TheMikeyR how do i compile in Windows platform, as example you shown above i believe that using Linux platform right?
@mohdazly my bad didn't notice you've listed windows as platform. I don't know how to compile it in the windows platform.
[Realsense Customer Engineering Team Comment]
@mohdazly
You can use CMake GUI to check the "BUILD_PYTHON_BINDINGS" and change the "PYTHON_EXECUTABLE" to your anaconda python.exe in your environment path. For example "C:/Users/abcd/AppData/Local/Continuum/anaconda3/envs/
After compiling python folder finish(check the attached image), you should see output files under Debug/Release folder as attachment, few things to do as below :
- change the name of "pybackend2.cp36-win_amd64.pyd" to "pybackend2.pyd" and "pyrealsense2.cp36-win_amd64.pyd" to "pyrealsense2.pyd"
- copy "pybackend2.pyd", "pyrealsense2.pyd" and "realsense2.dll" to "DLLs" folder. For example "C:/Users/abcd/AppData/Local/Continuum/anaconda3/envs/
/DLLs" - copy "realsense2.lib" to "libs" folder. For example "C:/Users/abcd/AppData/Local/Continuum/anaconda3/envs/
/libs"
Done.
@RealSense-Customer-Engineering @carypai Thank you for your answer. Can you ellaborate more on changing "PYTHON_EXECUTABLE" to anaconda python.exe in environment path? I didn't get it.
I already did all the methods as mentioned above, still encouter the same problem.
Apparently, I manually copy file from RealSense SDK 2.0 (pyrealsense2.py & realsense2.dll) which is installed in my PC into site-packages under my anaconda virtual environment, what I had discovered that, it is only can be run well under Python v2.7 but for v3.5 and 3.6 the same problem are triggered.
I just want to confirm that, is it RealSense SDK 2.0 only support Python 2.7 or both Python 2 & 3?
[Realsense Customer Engineering Team Comment] @mohdazly
Please see the answers below:
- PYTHON_EXECUTABLE variable will be seen after you first time clicking the configure button in CMAKE with "BUILD_PYTHON_BINDINGS" checked.
- https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/ following the instruction to set up python virtual environment.
- You can also copy the files ("pyd" and "dll" files) to the folder "site-packages" without problem.
- activate your virtual environment.
Attach issue from official account, attached the image of activating the virtual environment and run example here
@RealSense-Customer-Engineering @carypai As attached picture shown that there is no PYTHON_EXECUTABLE variable after I checked the configure button "BUILD_PYTHON_BINDINGS". Could you guide me on this matter.

After you check the BUILD_PYTHON_BINDINGS, please click "configure" button again, then you will see the variable.

@carypai & @RealSense-Customer-Engineering thank you so much for your guidance.
I managed to run RealSense SDK 2.0 under my anaconda virtual environment for both python 2 & 3. Below, I'm summarizing the steps required based on my understanding, hopefully it will make it more clear for other people references.
- Run CMake Gui "cmake-gui.exe".
- On "Where is the source code:", click "Browse Source" button and configure the path on librealsense, for example "C:/Users/PCName/Desktop/librealsense".
- Create "build" folder on librealsense path folder. On "Where to build the binaries:", click button "Browse Build" button and configure the path as for example "C:/Users/PCName/Desktop/librealsense/build".
- Make sure that you check on "Grouped" and "Advanced" checkbox for easy to identify each node and variables.
- Then click "Configure" button.
- On "Specify the generator for this project", select you visual studio version, as for example "Visual Studio 14 2015 Win64"
- Then click "Finish" button.
- After configuring done, on "BUILD" node, check "BUILD_PYTHON_BINDINGS" checkbox button.
- Then click "Configure" button again.
- On "Ungrouped Entries", identify variable "PYTHON_EXECUTABLE", change the path to anaconda python.exe in your virtual environment path as for example "C:/Users/PCName/Anaconda3/envs//python.exe" or "C:/Users/abcd/AppData/Local/Continuum/anaconda3/envs//python.exe"
- Then click "Generate" button, after all configuring and generating successfully done, click "Open Project".
- After Visual Studio IDE open, then start compiling/debug the solution.
As refer to @RealSense-Customer-Engineering
After compiling python folder finish(check the attached image), you should see output files under "librealsense/build/Debug folder as attachment inside the build, few things to do as below :
- change the name of "pybackend2.cp36-win_amd64.pyd" to "pybackend2.pyd" and "pyrealsense2.cp36-win_amd64.pyd" to "pyrealsense2.pyd"
There are 2 methods on copying the
- copy "pybackend2.pyd", "pyrealsense2.pyd" and "realsense2.dll" to "DLLs" folder. For example "C:/Users/abcd/AppData/Local/Continuum/anaconda3/envs//DLLs"
- copy "realsense2.lib" to "libs" folder. For example "C:/Users/abcd/AppData/Local/Continuum/anaconda3/envs//libs"
OR
- You can also copy the files ("pyrealsense.2pyd" and "realsense2.dll" files) to the folder "site-packages" as for example : "C:\Users\PCName\Anaconda3\envs\EnvironmentName\Lib\site-packages".
To test that your SDK files are working well:-
- On Anaconda prompt, activate your environment by type, "activate EnvironmentName", below scenario will be shown on the prompt. "(EnvironmentName) C:\Users\PCName>"
- Then navigate the python example project as below example, and then hit "Enter" "(EnvironmentName) C:\Users\PCName>cd C:\Users\PCName\Desktop\librealsense\wrappers\python\examples"
- Then, type python and choose one of the projects as below, "(EnvironmentName) C:\Users\PCName\Desktop\librealsense\wrappers\python\examples>python python-tutorial-1-depth.py"
Below picture shown the list of python sample projects for RealSense

Hereby I close the issues as I already find the solutions.
Thank you.
Hello,
I have an error while genarating C-make file
I use python 3.5.6 ,conda envirionment and windows 10 pc
ERROR msg
Selecting Windows SDK version 10.0.10586.0 to target Windows 10.0.17134. Info: REALSENSE_VERSION_STRING=2.19.0 Setting Windows configurations Build for Windows > Win7 Use external libusb CMake Error at C:/Program Files/CMake/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:137 (message): Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE) C:/Program Files/CMake/share/cmake-3.14/Modules/FindPythonInterp.cmake:160 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) wrappers/python/third_party/pybind11/tools/FindPythonLibsNew.cmake:60 (find_package) wrappers/python/third_party/pybind11/tools/pybind11Tools.cmake:16 (find_package) wrappers/python/third_party/pybind11/CMakeLists.txt:33 (include)
Configuring incomplete, errors occurred! See also "C:/Users/rsr5le/Desktop/realsense/librealsense-2.19.0/bud/CMakeFiles/CMakeOutput.log". See also "C:/Users/rsr5le/Desktop/realsense/librealsense-2.19.0/bud/CMakeFiles/CMakeError.log".
Everybody! Are you understanding above all? Is it real difficult to use realsense camera in winodw as python? I give up!