【问题标题】:Installing pytesser安装 pytesser
【发布时间】:2013-03-12 02:53:47
【问题描述】:

我是 python 新手,想安装和使用 pytesser OCR 库。我安装的所有其他模块,我都使用了easy_install,它运行良好。但是 pytesser 是我必须使用 Google Code 的 .zip 文件手动安装的第一个。

根据自述文件 (https://code.google.com/p/pytesser/wiki/README) 中的说明,我将上下文提取到我的 C:\Python27\Scripts 文件中。但是,当我尝试时:

from pytesser import *

在 Python Shell 中,我收到以下错误:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    from pytesser import *
ImportError: No module named pytesser

有什么想法吗?视窗 7。Python 2.7。我使用 PIL、S​​crapy、Numpy 等模块的其他脚本运行良好。

谢谢, 汤姆

【问题讨论】:

  • 您的 pytesser 文件是否与导入语句所在的文件(您正在编写的文件)位于同一目录中?
  • 如何知道 python shell CLI 在哪里运行它的代码?

标签: python python-2.7 ocr tesseract


【解决方案1】:

我不确定这是否是理想的解决方案,但这对我有用。如果这有任何不正确,请纠正我。

  1. 解压文件夹并将其粘贴到您的 Python2x\Lib 文件夹中
  2. 将其重命名为 pytesser(我不太确定这是否是必要的步骤)
  3. 复制 tesseract.py 文件并将其重命名为 __init__.py
  4. 打开 __init__.py
  5. 将 tesseract_exe_name = "tesseract" 行更改为 tesseract_exe_name = 'C:\Python27\Lib\pytesser\tesseract'

完成。

【讨论】:

  • 我已经从google代码下载了pytesser,但是没有tesseract.py。我发现它实际上是python-tesseract (code.google.com/p/python-tesseract)。是你也安装的库吗?
  • 谢谢!这对我也很有效,只是我必须将初始化文件命名为 __init__.py
  • 另外我必须将行 import Image 更改为 from PIL import Image
  • 我不得不将 Image 的导入更改为 from PIL import Image
  • 对我来说,最后一步是'C:/Python27/Lib/site-packages/pytesser/tesseract'
【解决方案2】:

您不应将C:\Python27\Scripts 用于第三方模块,而应使用C:\Python27\Lib\site-packages

【讨论】:

【解决方案3】:

所以我使用的是 w10 64 位。 我花了一些时间来了解您必须如何安装它才能使用它。

如何:

https://code.google.com/archive/p/pytesser/downloads

下载pytesser_v0.0.1.zip

解压

在项目中移动文件

在pytesser.py中将import Image重命名为“from PIL import Image”

=== 享受吧。

【讨论】:

    【解决方案4】:

    对 Yaitzme 的进一步回答 - 您可能需要的另一个修复(我在 Windows 7 64 位上使用 Python Tools for Visual Studio)...

    将 pytesser.py 文件重命名为 __init__ 后,我必须在该行中添加一个双反斜杠,例如

    tesseract_exe_name = 'C:\Anaconda2\Lib\site-packages\pytesser\\tesseract'

    因为单个反斜杠 '\tesseract' 将 '\t' 解释为新的制表符符号并破坏了路径!把我的安装说明here

    【讨论】:

      【解决方案5】:

      我怀疑问题在于 Python 无法找到您的 C:\Python27\Scripts 目录,因为它不在您的 PYTHONPATH 中。

      当您运行import 命令时,Python 会在某些目录中查找文件,它们在此处被描述为http://docs.python.org/2/tutorial/modules.html#the-module-search-path

      您的主要选择是:

      1) 告诉 Python 查看您的 Scripts 文件夹。这涉及将文件夹添加到您的 Python 路径,请参阅此处How to add to the pythonpath in windows 7?

      2) 将您的脚本放在 Python 已经搜索过的文件夹中。这是 wRAR 的答案,要使用标准 Python 3rd-party 模块目录,请参阅此处http://docs.python.org/2/install/index.html#how-installation-works

      3) 在 Python 的当前目录中拥有 pytesser 文件。 import os 后跟os.getcwd() 将向您显示python 的当前目录,其中代码正在运行(在某种意义上)。 os.chdir("my/other/dir") 更改当前目录。详情请参阅How to know/change current directory in Python shell?

      【讨论】:

      • OP试图将模块安装到系统中,而不是从本地目录导入。
      • 根据code.google.com/p/pytesser/wiki/README“PyTesser 在此版本中没有安装功能。”因此,他的 Python 路径中需要有 .py 文件。我在回答的最后提到了这个问题。还是我弄错了?
      • 是的,他的 Python 路径中需要有 .py 文件,这与工作目录无关。您答案的最后一部分假设您只有在更改错误的工作目录后才能从 PYTHONPATH 导入模块。
      • 我正在检查问题确实是 PYTHONPATH,在同一个目录中可以解决这个问题docs.python.org/2/tutorial/modules.html#the-module-search-path
      • 是的,现在最后一部分的错误更少了,尽管原始问题仍然没有必要,因为我们知道 OP 做错了什么。
      【解决方案6】:

      你可能搞错了。 我昨天尝试了pytesser,也许你不应该将pytesser文件放入脚本文件夹中。尝试工作目录以及您的代码。

      >>> import pytesser
      >>> print pytesser
      <module 'pytesser' from 'E:\Desktop\jiaoben\OCR\pytesser.pyc'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多