KeCh96 / hello-world

a hello-world code
0 stars 0 forks source link

dd #1

Open KeCh96 opened 6 years ago

KeCh96 commented 6 years ago

My project can work on both Windows and Linux. According to my project, I only need a solution for any of the following 2 problems:

  1. Building python3 wrapper on Windows10
  2. Building python2 or python3 wrapper on Ubuntu16.04

    I tried many methods, and my problems are as below:

  1. Building python3 wrapper on Windows10 As you say, the only way to build python3 wrapper on Windows is to use CMake and build from source. I guess that building python2 wrapper on Linux may be easier, so I give up Windows solution.

  2. Building python2 or python3 wrapper on Ubuntu16.04 I followed the tutorial for Linux . I run realsense-viewer and launched the SR300 GUI successfully. Then I run sudo apt-get install librealsense2-dev and sudo apt-get install librealsense2-dbg successfully. However, when I wanted to run g++ -std=c++11 filename.cpp -lrealsense2, I did not know where the "filename.cpp" is . So I skipped that step. Then I browsed python wrapper tutorial for Linux and found I need to install CMake. Is there any method to build python wrapper without using CMake? I want to copy pyrealsense2.pyd and realsense2.dll to my program. But at this moment, I cannot find pyrealsense2.pyd and realsense2.dll in my system. Did I have some step missing?

    After these attempts, I found another tutorial pyrealsense 2.2, and pray this can be an easy python wrapper building tool. But pip install pyrealsense run into an error:

Collecting pyrealsense Downloading pyrealsense-2.2.tar.gz (60kB) 100% |████████████████████████████████| 61kB 46kB/s Requirement already satisfied: numpy in ./anaconda2/lib/python2.7/site-packages (from pyrealsense) Requirement already satisfied: cython in ./anaconda2/lib/python2.7/site-packages (from pyrealsense) Requirement already satisfied: pycparser in ./anaconda2/lib/python2.7/site-packages (from pyrealsense) Requirement already satisfied: six in ./anaconda2/lib/python2.7/site-packages (from pyrealsense) Building wheels for collected packages: pyrealsense Running setup.py bdist_wheel for pyrealsense ... error Complete output from command /root/anaconda2/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-k1ws2H/pyrealsense/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmpQDkpd8pip-wheel- --python-tag cp27: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-2.7 creating build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/extlib.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/offline.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/utils.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/extstruct.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/stream.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/core.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/init.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/constants.py -> build/lib.linux-x86_64-2.7/pyrealsense running build_ext building 'pyrealsense.rsutilwrapper' extension creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/pyrealsense gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/root/anaconda2/lib/python2.7/site-packages/numpy/core/include -I/usr/local/include/librealsense -I/root/anaconda2/include/python2.7 -c pyrealsense/rsutilwrapper.cpp -o build/temp.linux-x86_64-2.7/pyrealsense/rsutilwrapper.o cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ In file included from /root/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1777:0, from /root/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18, from /root/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4, from pyrealsense/rsutilwrapper.cpp:474: /root/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

warning "Using deprecated NumPy API, disable it by " \

^

pyrealsense/rsutilwrapper.cpp:477:16: fatal error: rs.h: No file or directory compilation terminated. error: command 'gcc' failed with exit status 1


Failed building wheel for pyrealsense Running setup.py clean for pyrealsense Failed to build pyrealsense Installing collected packages: pyrealsense Running setup.py install for pyrealsense ... error Complete output from command /root/anaconda2/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-k1ws2H/pyrealsense/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-taxuSu-record/install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build/lib.linux-x86_64-2.7 creating build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/extlib.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/offline.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/utils.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/extstruct.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/stream.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/core.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/init.py -> build/lib.linux-x86_64-2.7/pyrealsense copying pyrealsense/constants.py -> build/lib.linux-x86_64-2.7/pyrealsense running build_ext building 'pyrealsense.rsutilwrapper' extension creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/pyrealsense gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/root/anaconda2/lib/python2.7/site-packages/numpy/core/include -I/usr/local/include/librealsense -I/root/anaconda2/include/python2.7 -c pyrealsense/rsutilwrapper.cpp -o build/temp.linux-x86_64-2.7/pyrealsense/rsutilwrapper.o cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ In file included from /root/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1777:0, from /root/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18, from /root/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4, from pyrealsense/rsutilwrapper.cpp:474: /root/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

warning "Using deprecated NumPy API, disable it by " \

  ^
pyrealsense/rsutilwrapper.cpp:477:16: fatal error: rs.h: No file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

----------------------------------------

Command "/root/anaconda2/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-k1ws2H/pyrealsense/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-taxuSu-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-k1ws2H/pyrealsense/

I am almost crazy...

Could you please help me?

KeCh96 commented 6 years ago

Thank you very much!! I followed your guide, but faced some error when make -j4:

[ 59%] Linking CXX executable rs-pointcloud In file included from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/pytypes.h:12:0, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/cast.h:13, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/attr.h:13, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:36, from /home/chengke/librealsense/wrappers/python/pybackend.cpp:1: /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/common.h:70:20: fatal error: Python.h: No such file or directory compilation terminated. wrappers/python/CMakeFiles/pybackend2.dir/build.make:158: recipe for target 'wrappers/python/CMakeFiles/pybackend2.dir/pybackend.cpp.o' failed make[2]: [wrappers/python/CMakeFiles/pybackend2.dir/pybackend.cpp.o] Error 1 CMakeFiles/Makefile2:1261: recipe for target 'wrappers/python/CMakeFiles/pybackend2.dir/all' failed make[1]: [wrappers/python/CMakeFiles/pybackend2.dir/all] Error 2 make[1]: 正在等待未完成的任务.... /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status examples/capture/CMakeFiles/rs-capture.dir/build.make:98: recipe for target 'examples/capture/rs-capture' failed make[2]: [examples/capture/rs-capture] Error 1 CMakeFiles/Makefile2:307: recipe for target 'examples/capture/CMakeFiles/rs-capture.dir/all' failed make[1]: [examples/capture/CMakeFiles/rs-capture.dir/all] Error 2 /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status examples/pointcloud/CMakeFiles/rs-pointcloud.dir/build.make:176: recipe for target 'examples/pointcloud/rs-pointcloud' failed examples/multicam/CMakeFiles/rs-multicam.dir/build.make:98: recipe for target 'examples/multicam/rs-multicam' failed make[2]: [examples/pointcloud/rs-pointcloud] Error 1 make[2]: [examples/multicam/rs-multicam] Error 1 CMakeFiles/Makefile2:417: recipe for target 'examples/multicam/CMakeFiles/rs-multicam.dir/all' failed make[1]: [examples/multicam/CMakeFiles/rs-multicam.dir/all] Error 2 CMakeFiles/Makefile2:472: recipe for target 'examples/pointcloud/CMakeFiles/rs-pointcloud.dir/all' failed make[1]: [examples/pointcloud/CMakeFiles/rs-pointcloud.dir/all] Error 2 Makefile:127: recipe for target 'all' failed make: [all] Error 2

I use 'make -j4 -i' to ignore the errors, and get the following result:

[ 20%] Built target realsense-file In file included from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/pytypes.h:12:0, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/cast.h:13, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/attr.h:13, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:36, from /home/chengke/librealsense/wrappers/python/pybackend.cpp:1: /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/common.h:70:20: fatal error: Python.h: 没有那个文件或目录 compilation terminated. [ 20%] Linking CXX shared library pybackend2.cpython-35m-x86_64-linux-gnu.so c++: error: CMakeFiles/pybackend2.dir/pybackend.cpp.o: 没有那个文件或目录 [ 29%] Built target pybackend2 [ 65%] Built target realsense2 [ 66%] Linking CXX executable rs-pointcloud [ 66%] Linking CXX executable rs-multicam [ 67%] Built target rs-save-to-disk [ 68%] Linking CXX executable rs-capture [ 69%] Linking CXX executable rs-align /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status [ 69%] Built target rs-capture /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status [ 70%] Built target rs-multicam [ 73%] Built target rs-pointcloud [ 74%] Linking CXX executable rs-sensor-control [ 75%] Built target rs-color [ 77%] Built target rs-depth [ 78%] Built target rs-distance [ 80%] Built target rs-terminal /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status [ 82%] Built target rs-align [ 86%] Built target rs-fw-logger [ 87%] Built target rs-enumerate-devices [ 88%] Built target rs-data-collect [ 89%] Built target live-test /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status [ 89%] Built target rs-sensor-control [ 90%] Building CXX object wrappers/python/CMakeFiles/pyrealsense2.dir/python.cpp.o [ 91%] Linking CXX executable rs-depth-quality [ 92%] Linking CXX executable realsense-viewer In file included from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/pytypes.h:12:0, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/cast.h:13, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/attr.h:13, from /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/pybind11.h:36, from /home/chengke/librealsense/wrappers/python/python.cpp:1: /home/chengke/librealsense/wrappers/python/third_party/pybind11/include/pybind11/common.h:70:20: fatal error: Python.h: 没有那个文件或目录 compilation terminated. [ 93%] Linking CXX shared library pyrealsense2.cpython-35m-x86_64-linux-gnu.so c++: error: CMakeFiles/pyrealsense2.dir/python.cpp.o: 没有那个文件或目录 [ 93%] Built target pyrealsense2 /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status [ 96%] Built target realsense-viewer /usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status [100%] Built target rs-depth-quality

Then I found librealsense2.so in the build file, and its color is light blue in the ubuntu common line, which means symbolic link file. Then I run cdll.LoadLibrary('librealsense2.so') in python IDE successfully. But I do not know how to use this file in python. could you please tell me how to use this 'librealsense2.so' to capture images in python?

Then I go to ./wrappers/python, and found pyrealsense2.cpython-35m-x86_64-linux-gnu.so, but its color is red, which means compressed file. I run cdll.LoadLibrary('pyrealsense2.cpython-35m-x86_64-linux-gnu.so') in python IDE and get error:

OSError: pybackend2.cpython-35m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory

I have written the path in /etc/ld.so.conf but the error still occur. I wonder whether the file is complied successfully or not?