Ubuntu 16.04 安装pyk4a

pyk4a简介

pyk4a的github地址

准备工作

  • 在Ubuntu 16.04上安装Azure Kinect DK的SDK,参考教程
  • 将libk4a.so所在的目录添加到LD_LIBRARY_PATH

安装过程

第一次安装(失败)

按照pyk4a的README,输入命令pip install pyk4a,安装失败,错误信息如下。从错误信息中可以看出pyk4a的安装需要使用c++11,于是修改pyk4a源码的setup.py,使其使用c++11。

Collecting pyk4a
  Downloading pyk4a-1.2.4.tar.gz (21 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting python-version>="3.4"
  Downloading python_version-0.0.2-py2.py3-none-any.whl (3.4 kB)
Requirement already satisfied: numpy in /home/castiel/anaconda3/envs/torch_env/lib/python3.7/site-packages (from pyk4a) (1.20.3)
Building wheels for collected packages: pyk4a
  Building wheel for pyk4a (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/castiel/anaconda3/envs/torch_env/bin/python /home/castiel/.local/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmppwwsd5ij
       cwd: /tmp/pip-install-p74g5k84/pyk4a
  Complete output (39 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.7
  creating build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/pyk4a.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/__init__.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/playback.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/record.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/calibration.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/errors.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/capture.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/results.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/transformation.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/config.py -> build/lib.linux-x86_64-3.7/pyk4a
  copying pyk4a/py.typed -> build/lib.linux-x86_64-3.7/pyk4a
  running build_ext
  building 'k4a_module' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/pyk4a
  gcc -pthread -B /home/castiel/anaconda3/envs/torch_env/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip-build-env-3n5i9h__/overlay/lib/python3.7/site-packages/numpy/core/include -I/home/castiel/anaconda3/envs/torch_env/include/python3.7m -c pyk4a/pyk4a.cpp -o build/temp.linux-x86_64-3.7/pyk4a/pyk4a.o
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  In file included from /tmp/pip-build-env-3n5i9h__/overlay/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1944:0,
                   from /tmp/pip-build-env-3n5i9h__/overlay/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                   from /tmp/pip-build-env-3n5i9h__/overlay/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                   from pyk4a/pyk4a.cpp:2:
  /tmp/pip-build-env-3n5i9h__/overlay/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   #warning "Using deprecated NumPy API, disable it with " \
    ^
  In file included from /usr/include/c++/5/cinttypes:35:0,
                   from /usr/local/include/k4a/k4a.h:11,
                   from pyk4a/pyk4a.cpp:4:
  /usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
   #error This file requires compiler and library support \
    ^
  /tmp/pip-build-env-3n5i9h__/overlay/lib/python3.7/site-packages/setuptools/dist.py:694: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead
    % (opt, underscore_opt))
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pyk4a
Failed to build pyk4a
ERROR: Could not build wheels for pyk4a which use PEP 517 and cannot be installed directly
WARNING: You are using pip version 20.2.3; however, version 21.1.2 is available.
You should consider upgrading via the '/home/castiel/anaconda3/envs/torch_env/bin/python -m pip install --upgrade pip' command.

第二次安装(成功)

  • 从github上下载pyk4a的源码,并修改setup.py
from setuptools import setup, Extension

import sys
if sys.version_info[0] == 2:
    sys.exit("Python 2 is not supported.")

# Enables --editable install with --user
# https://github.com/pypa/pip/issues/7953
import site
site.ENABLE_USER_SITE = "--user" in sys.argv[1:]

# Bypass import numpy before running install_requires
# https://stackoverflow.com/questions/54117786/add-numpy-get-include-argument-to-setuptools-without-preinstalled-numpy
class get_numpy_include:
    def __str__(self):
        import numpy
        return numpy.get_include()


module = Extension('k4a_module',
                   sources=['pyk4a/pyk4a.cpp'],
                   include_dirs=[get_numpy_include()],
                   language='c++',
                   libraries=['k4a', 'k4arecord'],
                   extra_compile_args=['-std=c++11'],
                   extra_link_args=['-std=c++11'])

setup(ext_modules=[module])
  • 使用setup.py安装pyk4a
python setup.py build
python setup.py install
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值