在CentOS上安装OpenCV with python module出错了 [英] Installing OpenCV with python module on CentOS goes wrong

查看:772
本文介绍了在CentOS上安装OpenCV with python module出错了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行此命令以使用Python模块安装OpenCV时

  cmake ../ -DCMAKE_BUILD_TYPE = RELEASE 
-DCMAKE_INSTALL_PREFIX = / usr / local
-DBUILD_EXAMPLES = ON
-DBUILD_NEW_PYTHON_SUPPORT = ON
-DINSTALL_PYTHON_EXAMPLES = ON
-DPYTHON_EXECUTABLE = / usr / local / bin / python2.7
-DPYTHON_INCLUDE_DIR = / usr / local / include / python2.7 /
-DPYTHON_LIBRARY = / usr / local / lib / python2.7 / config / libpython2.7.a
-DPYTHON_NUMPY_INCLUDE_DIR = / usr /local/lib/python2.7/site-packages/numpy/core/include/
-DPYTHON_PACKAGES_PATH = / usr / local / lib / python2.7 / site-packages /
-DBUILD_PYTHON_SUPPORT = ON

我收到此错误讯息。

  / usr / bin / ld:/usr/local/lib/python2.7/config/libpython2.7.a(abstract.o):重定位R_X86_64_32 
对`.rodata。 str1.8'不能在创建共享对象时使用;重新编译-fPIC
/usr/local/lib/python2.7/config/libpython2.7.a:无法读取符号:错误值
collect2:ld返回1退出状态
make [2]:*** [lib / cv2.so]错误1
make [1]:*** [modules / python / CMakeFiles / opencv_python.dir / all]错误2
make: ** [全部]错误2

我无法理解错误和错误消息。



有人可以告诉我这是什么问题吗?



顺便说一下,我的操作系统CentOS。



我使用Python2.7.5

解决方案

题。
希望有人遇到同样的问题,在短时间内找到出路。



1.首先,只是使用yum
更新所有pagackages在安装OpenCV时,有几个错误归因于依赖性问题。

  sudo yum update --skip-broken 


$ b b

2.使用--enable-shared重建Python。
使用python模块的OpenCV需要正确构建libpython2.7.so文件。
然而,如果你刚刚构建python没有这个配置,很可能你没有这个文件。
libpython2.7.a是不够的。在我的情况下,当我提到libpython2.7.a是一个python库源,它不断崩溃。



所以..下载python 2.7.5(或类似的东西),并重新配置这样。

  ./ configure --enable-shared 
make
make install

现在你可能会得到libpython2.7.so和libpython2.7.so.1.0



3.使用python模块。
这是我在安装时编码的。

  cmake ../ -DCMAKE_BUILD_TYPE = RELEASE 
-DCMAKE_INSTALL_PREFIX = / usr / local
-DBUILD_EXAMPLES = ON
-DBUILD_NEW_PYTHON_SUPPORT = ON
-DINSTALL_PYTHON_EXAMPLES = ON
-DPYTHON_EXECUTABLE = / usr / local / bin / python2.7
- DPYTHON_INCLUDE_DIR = / usr / local / include / python2.7 /
-DPYTHON_LIBRARY = / usr / local / lib / libpython2.7.so.1.0
-DPYTHON_NUMPY_INCLUDE_DIR = / usr / local / lib / python2。 7 / site-packages / numpy / core / include /
-DPYTHON_PACKAGES_PATH = / usr / local / lib / python2.7 / site-packages /
-DBUILD_PYTHON_SUPPORT = ON



就是这样。


when I run this command to install OpenCV with Python module

cmake ../ -DCMAKE_BUILD_TYPE=RELEASE 
-DCMAKE_INSTALL_PREFIX=/usr/local 
-DBUILD_EXAMPLES=ON 
-DBUILD_NEW_PYTHON_SUPPORT=ON 
-DINSTALL_PYTHON_EXAMPLES=ON 
-DPYTHON_EXECUTABLE=/usr/local/bin/python2.7 
-DPYTHON_INCLUDE_DIR=/usr/local/include/python2.7/ 
-DPYTHON_LIBRARY=/usr/local/lib/python2.7/config/libpython2.7.a 
-DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/site-packages/numpy/core/include/ 
-DPYTHON_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages/ 
-DBUILD_PYTHON_SUPPORT=ON

I get this error message.

/usr/bin/ld: /usr/local/lib/python2.7/config/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/python2.7/config/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

I can't understand what is wrong and the error message.

Is there someone who can tell me what is wrong with this?

By the way, My OS is CentOS.

and I use Python2.7.5

解决方案

I answer my own question. hope someone who suffers the same problem find a way out of it in a short time.

1.First of all, just update all pagackages using yum I got several bugs attributed to dependency issues when installing OpenCV.

 sudo yum update --skip-broken

2.Rebuild your Python with "--enable-shared". OpenCV with python module requires the "libpython2.7.so" file to be built correctly. However if you have just built python without this configuration, it's likely that you do not have this file. "libpython2.7.a" is not enough. In my case, when I refer libpython2.7.a to be a python library source it crashed down continuously.

So.. download python 2.7.5 (or something like this), and reconfigure like this.

./configure --enable-shared
make
make install

Now you might get "libpython2.7.so" and "libpython2.7.so.1.0"

3.Build your OpenCV with python module. this is what I coded on installation. I guess this example help you kick your problem out.

cmake ../ -DCMAKE_BUILD_TYPE=RELEASE 
-DCMAKE_INSTALL_PREFIX=/usr/local 
-DBUILD_EXAMPLES=ON 
-DBUILD_NEW_PYTHON_SUPPORT=ON 
-DINSTALL_PYTHON_EXAMPLES=ON 
-DPYTHON_EXECUTABLE=/usr/local/bin/python2.7 
-DPYTHON_INCLUDE_DIR=/usr/local/include/python2.7/ 
-DPYTHON_LIBRARY=/usr/local/lib/libpython2.7.so.1.0 
-DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/site-packages/numpy/core/include/ 
-DPYTHON_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages/ 
-DBUILD_PYTHON_SUPPORT=ON

That's all.

这篇关于在CentOS上安装OpenCV with python module出错了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆