在 CentOS 上使用 python 模块安装 OpenCV 出错 [英] Installing OpenCV with python module on CentOS goes wrong

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

问题描述

当我运行这个命令来安装带有 Python 模块的 OpenCV 时

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

我收到此错误消息.

/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?

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

By the way, My OS is CentOS.

我用的是 Python2.7.5

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.首先,使用yum更新所有的包我在安装 OpenCV 时遇到了几个归因于依赖问题的错误.

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. 使用--enable-shared"重建您的 Python.带有 python 模块的 OpenCV 需要正确构建libpython2.7.so"文件.但是,如果您刚刚构建了没有此配置的 python,则很可能您没有此文件.libpython2.7.a"还不够.就我而言,当我将 libpython2.7.a 称为 python 库源时,它不断崩溃.

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.

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

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

./configure --enable-shared
make
make install

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

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

3. 使用 python 模块构建您的 OpenCV.这是我在安装时编码的.我想这个例子可以帮助你解决问题.

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

就是这样.

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

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