当前位置首页 > CentOS知识

CentOS6安装python2.7和mod_wsgi运行pyocr[tesseract]

阅读次数:193 次  来源:admin  发布时间:

最新版本的tesseract-ocr 3.0.4 需要运行于python2.7版本以上,因此需要升级系统中默认的2.6版本python及Mod_WSGI

1,下载安装Python-2.7.10

>tar xJvf  Python-2.7.10.tar6.xz
>cd  Python-2.7.10
# 这里,必须用–enable-shared,生成动态库,否则会遇到wsgi不能编译的问题。
>./configure --enable-shared  
>make && make install

#替换原来的默认pytho

gt;mv /usr/bin/python /usr/bin/python2.6

gt;ln -s /usr/local/bin/python2.7 /usr/bin/pytho

#设置lib路径

gt;ldconfig /usr/local/li

#查看python状态

gt;python -V

2,安装python2.7的mod_wsgi

>pip install mod_wsgi

如果安装python2.7.10时没有加入--enable-shared参数,安装mod_wsgi时就会报如下错误:"recompile with -fPIC"

......

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

apxs:Error: Command failed with rc=65536

3, 替换系统默认Mod_wsgi

>mv /usr/lib64/httpd/modules/mod_wsgi.so /usr/lib64/httpd/modules/mod_wsgi.so.origin 
>ln -s /usr/local/lib/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so /usr/lib64/httpd/modules/mod_wsgi.so

4,运行apache,报错找不到ocr模块,然而在调试环境下没有问题,经查看pyocr的源码发现,pyocr.get_available_tools() 是通过在环境变量os.environ["PATH"]中查看有没有tesseract命令,因此需要将tesseract的安装路径/usr/local/bin/tesseract加入PATH中,然后重新启动,或者在python程序中自己加入路径/usr/local/bi

上一篇:apache配置php
下一篇:apachenginxphp不显示版本号