在使用pytesser做图片文字识别时遇到 WindowsError: [Error 2] 错误,报错内容如下:

Traceback (most recent call last):
File "E:/Code/Captcha/ChinaMobileEC/recogCaptcha.py", line 37, in <module>
print pytesser.image_to_string(out)
File "E:\Code\Captcha\pytesser\pytesser.py", line 36, in image_to_string
call_tesseract(scratch_image_name, scratch_text_name_root)
File "E:\Code\Captcha\pytesser\pytesser.py", line 25, in call_tesseract
proc = subprocess.Popen(args)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2]

WindowsError: [Error 2] 的意思是系统找不到指定的文件。

查看pytesser中的代码,其实就是一个调用 tesseract.exe 识别图片的过程,其中代码如下:

tesseract_exe_name = 'tesseract'

def call_tesseract(input_filename, output_filename):
"""Calls external tesseract.exe on input file (restrictions on types),
outputting output_filename+'txt'"""
args = [tesseract_exe_name, input_filename, output_filename]
proc = subprocess.Popen(args)
retcode = proc.wait()
if retcode != 0:
errors.check_for_errors()

就是调用 subprocess.Popen() 执行 tesseract input_filename output_filename, 这样会将识别结果写到out_filename的txt文件。这条命令你可以直接在cmd中到 tesseract.exe 目录下运行,也能看到识别结果。pytesser其实就是调用这个命令识别,然后读取结果返回。

所以上面错误中所说的找不到的文件就是指 tesseract.exe。所以解决这个问题的方法有两种:

第一种时将 tesseract.exe 所在路径添加到搜索路径,这样无论在哪儿执行 tesseract 系统都能找到。

第二种是修改 pytesser 中的代码, 将 tesseract 换成绝对路径即可:

import os

pwd = os.path.dirname(__file__)

# 将原来的 tesseract_exe_name='tesseract' 改成绝对路径
tesseract_exe_name = os.path.join(pwd,'tesseract')

博客地址: http://www.spiderpy.cn/blog/detail/35

pytesser模块WindowsError错误解决方法的更多相关文章

  1. pygame模块使用时出现AttributeError: module ‘pygame’ has no attribute '…'错误解决方法

    pygame模块使用时出现AttributeError: module 'pygame' has no attribute '-'错误解决方法 首先在pygame中存在init()模块,出现这样的问题 ...

  2. Nginx的500,502,504错误解决方法

    Nginx的500,502,504错误解决方法 一.解决500错误: 1.500错误指的是服务器内部错误,也就是服务器遇到意外情况,而无法履行请求. 2.500错误一般有几种情况: (1)web脚本错 ...

  3. SQL SERVER 9003错误解决方法 只适用于SQL2000

    SQLSERVER 9003错误解决方法 只适用于SQL2000 (只适用于SQL2000) "无法打开新数据库 'POS'.CREATE DATABASE 中止. (Microsoft S ...

  4. New XAMPP security concept:错误解决方法

    New XAMPP security concept:错误解决方法 (2014-03-06 16:07:46) 转载▼   分类: php 在Linux上配置xampp后远程访问域名报错: New X ...

  5. hadoop本地库与系统版本不一致引起的错误解决方法

    hadoop本地库与系统版本不一致引起的错误解决方法 部署hadoop的集群环境为 操作系统 centos 5.8 hadoop版本为cloudera   hadoop-0.20.2-cdh3u3 集 ...

  6. mysql Access denied for user root@localhost错误解决方法总结(转)

    mysql Access denied for user root@localhost错误解决方法总结(转) mysql Access denied for user \'root\'@\'local ...

  7. Eclipse 出现Some sites could not be found. See the error log for more detail.错误 解决方法

    Eclipse 出现Some sites could not be found.  See the error log for more detail.错误 解决方法 Some sites could ...

  8. eWebeditor编辑器上传图片路径错误解决方法[疑难杂症]【转,作者:unvs】

    做了一个多版本的网站,后台用的编辑器是eWebeditor,NET版,后面发现上传图片或者文件之后,路径错误无法显示,必须手工修改才行.. 为了更清楚的说明问题,我下面会说的比较详细,首先是网站文件框 ...

  9. 网站启动SSL, http变为https后,session验证码错误解决方法

    网站启动SSL, http变为https后,session验证码错误解决方法   最近公司需要后台启动安全证书,证书安装完毕后,后台老提示 验证码错误,经过几天的研究,此问题已经得到有效解决,现把方法 ...

随机推荐

  1. SpingCloud之feign框架调用

    1.生产者(没有什么特殊性) pom.xml <?xml version="1.0" encoding="UTF-8"?> <project ...

  2. 【bzoj2329】[HNOI2011]括号修复 Splay

    题目描述 题解 Splay 由于有区间反转操作,因此考虑Splay. 考虑答案:缩完括号序列后剩下的一定是 $a$ 个')'+ $b$ 个'(',容易发现答案等于 $\lceil\frac a2\rc ...

  3. The Toll! Revisited UVA - 10537(变形。。)

    给定图G=(V,E)G=(V,E),VV中有两类点,一类点(AA类)在进入时要缴纳1的费用,另一类点(BB类)在进入时要缴纳当前携带金额的1/20(不足20的部分按20算) 已知起点为SS,终点为TT ...

  4. [BJWC2011]元素 线性基

    题面 题面 题解 一个方案合法,当且仅当选取的01串凑不出0. 因此就是要使得选取的01串全在线性基内,具体原因可以看这道题:[CQOI2013]新Nim游戏 线性基 要使得魔力值最大,只需要按法力值 ...

  5. Hadoop1重新格式化HDFS

    注意:原来的数据全部被清空了.产生了一个新的hdfs 1. 删除已有目录 1.1 查看hdfs-site.xml 将 dfs.name.dir和dfs.data.dir所指定的目录删除 vim hdf ...

  6. 【learning】快速沃尔什变换FWT

    问题描述 已知\(A(x)\)和\(B(x)\),\(C[i]=\sum\limits_{j\otimes k=i}A[j]*B[k]\),求\(C\) 其中\(\otimes\)是三种位运算的其中一 ...

  7. 03-树2. List Leaves (25) 二叉树的层序遍历

    03-树2. List Leaves (25) 题目来源:http://www.patest.cn/contests/mooc-ds/03-%E6%A0%912 Given a tree, you a ...

  8. Hdu3022 Sum of Digits

    Sum of Digits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  9. 防止xss攻击的核心代码

    public class XssFilter implements Filter { @Override public void destroy() { } /** * 过滤器用来过滤的方法 */ @ ...

  10. 6.UiWatcher API 详细介绍

    Tip: 1.监听器不是完能的,所以若用例需要设置监听器防止用例被打断,最好把延迟时间调高一点 2.UiDevice是不会触发监听功能的 3.监听器在方法体或者循环体中是程序还是会被打断的 4.监听器 ...