在Heroku上安装Python支持的OpenCV

在Heroku上安装Python支持的OpenCV

本文介绍了在Heroku上安装Python支持的OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装OpenCV以便与Python一起使用。第一次安装很顺利;但是,我错过了 cv2.so 文件。然后我添加了 -D BUILD_NEW_PYTHON_SUPPORT = ON ,希望它能为我创建 cv2.so 文件。 p>

完整命令:

  cmake -D CMAKE_INSTALL_PREFIX = $ {target}  - D CMAKE_FIND_ROOT_PATH = $ {target} -D CMAKE_BUILD_TYPE = RELEASE -D BUILD_NEW_PYTHON_SUPPORT = ON -D BUILD_SHARED_LIBS = OFF -D CMAKE_SHARED_LINKER_FLAGS = -  fPIC.. 

大约92%的OpenCV出现以下错误:

 目标opencv_python的扫描依赖关系
[92%]构建CXX对象模块/ python / CMakeFiles / opencv_python.dir / src2 / cv2.cpp.o
链接CXX共享库../../lib/cv2.so
/ usr / bin / ld:/usr/local/lib/libpython2.7.a(abstract.o):在创建共享对象时,无法使用针对`.rodata.str1.8'的重定位R_X86_64_32;使用-fPIC重新编译
/usr/local/lib/libpython2.7.a:无法读取符号:错误值
collect2:ld返回1退出状态
make [2]:** * [lib / cv2.so]错误1
make [1]:*** [modules / python / CMakeFiles / opencv_python.dir / all]错误2
make:*** [all]错误2
错误:编译失败,退出2

运行默认版本的Python 2.7.6 Heroku安装。我遇到了一些提示需要 python-dev 的帖子,但它看起来像是开发者头文件已经存在()。



我使用自定义,如果有任何帮助的话。

解决方案

显然Python需要用 --enable-shared 标志传入以使 libpython2.7.so libpython2.7.so.1.0 被创建。使用Python模块的OpenCV需要 libpython2.7.so



  ./ configure --enable-shared 
make
make install

确保在编译时传入 -D BUILD_NEW_PYTHON_SUPPORT = ON CMake标志OpenCV。


I'm attempting to install OpenCV for use with Python. The first install went great; however, I was missing the cv2.so file. I then added -D BUILD_NEW_PYTHON_SUPPORT=ON in hopes that it would create the cv2.so file for me.

Full command:

cmake -D CMAKE_INSTALL_PREFIX=${target} -D CMAKE_FIND_ROOT_PATH=${target} -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_SHARED_LIBS=OFF -D CMAKE_SHARED_LINKER_FLAGS="-fPIC" ..

Around 92%, OpenCV fails with the following:

Scanning dependencies of target opencv_python
    [ 92%] Building CXX object modules/python/CMakeFiles/opencv_python.dir/src2/cv2.cpp.o
    Linking CXX shared library ../../lib/cv2.so
/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/cv2.so] Error 1
make[1]: *** [modules/python/CMakeFiles/opencv_python.dir/all] Error 2
make: *** [all] Error 2
ERROR: Build failed, exited 2

Running the default version of Python 2.7.6 that Heroku installs. I've come across a few posts that suggest the need for python-dev, but it looks like the dev headers are already there (Screenshot).

I'm using a custom buildpack if that's of any help.

解决方案

Apparently Python needs to be compiled with the --enable-shared flag passed in so that libpython2.7.so and libpython2.7.so.1.0 are created. OpenCV with the Python module requires libpython2.7.so.

To fix, compile python from source like so:

./configure --enable-shared
make
make install

Make sure to pass in the -D BUILD_NEW_PYTHON_SUPPORT=ON CMake flag when compiling OpenCV.

这篇关于在Heroku上安装Python支持的OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:25