First off, I would like to say that I know pytesser is not for Python 3.4, but I read from http://ubuntuforums.org/archive/index.php/t-1916011.html that pytesser should also work for Python 3. I just installed pytesser and I am trying to read a file.

首先,我想说我知道pytesser不适合Python 3.4,但是我从http://ubuntuforums.org/archive/index.php/t-1916011.html中读到pytesser也应该适合Python 3。我刚刚安装了pytesser,我正在尝试读取一个文件。

from pytesser import *
from PIL import Image
image = Image.open('/Users/William/Documents/Science/PYTHON/textArea01.png')

No problems there, but when I use

这里没有问题,但是当我使用的时候

print (image_to_string(image))

it comes up with this:

结果是这样的:

Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
    print (image_to_string(image))
NameError: name 'image_to_string' is not defined

2 个解决方案

#1


3

Your code will not work for Python 3. The reason is because when you do from pytesser import * (or simply import it in the first place), the if __name__ == '__main__' conditional will be True, and the code below it will run.

您的代码对Python 3不起作用。原因是,当您从pytesser导入*(或简单地导入它)时,如果__name__ == '__main__'条件将是正确的,下面的代码将运行。

As I'm sure you're aware, in Python 3, print is no longer a statement but a function. Hence, a SyntaxError will occur at the line print text.

我相信您已经知道,在Python 3中,print不再是一个语句,而是一个函数。因此,行打印文本将出现一个SyntaxError。

I'm not sure why you're not seeing this SyntaxError in your code, but if this error passed silently, that means that nothing was imported in the first place, hence the error.

我不知道为什么您没有在代码中看到这个SyntaxError,但是如果这个错误是悄无声息地传递的,那就意味着首先没有导入任何东西,因此出现了错误。

To fix this, use Python 2.7.

要解决这个问题,请使用Python 2.7。

Python 2.7:

Python 2.7:

>>> from pytesser import *
>>> print image_to_string
<function image_to_string at 0x10057ec08>

Python 3:

Python 3:

>>> from pytesser import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./pytesser.py", line 61
    print text
             ^
SyntaxError: invalid syntax

更多相关文章

  1. 八大经典排序算法基本思想及代码实现(插入排序,希尔排序,选择排序,
  2. UNIX-LINUX编程实践教程->第八章->实例代码注解->写一个简单的sh
  3. Linux下objdump查看C程序编译后的汇编代码
  4. wget在linux中安装出现错误解决办法
  5. busybox1.19.3编译错误解决办法
  6. 打开“保存命令历史记录时遇到错误”时的Matlab错误
  7. 编译android源码时,jack server 出现out of memory error 错误的
  8. 如何从PHP的mail()失败中获取额外的错误信息?
  9. 软交换FreeSWITCH系统概要和源代码分析预备知识

随机推荐

  1. 解决php运行超时的方法
  2. php页面传值的方法
  3. 有关PHP中PDO连接数据库的详细教程与实际
  4. php中缓存的种类
  5. php访问数据库的过程
  6. php usort()函数的使用方法
  7. PHP——thinkphp5的详解介绍与使用
  8. variables_order参数详解
  9. 在php当中常量和变量的区别
  10. php中break的作用