Python 安装pytesser
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15567141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing pytesser
提问by Tom M.
I'm new to python and would like to install and use the pytesser OCR library. All of the other modules that I've installed, I've used easy_install, which has worked fine. But pytesser is the first that I've had to install by hand using Google Code's .zip file.
我是 python 新手,想安装和使用 pytesser OCR 库。我安装的所有其他模块都使用了easy_install,它运行良好。但是 pytesser 是我必须使用 Google Code 的 .zip 文件手动安装的第一个。
Per the instructions in the readme (https://code.google.com/p/pytesser/wiki/README) I extracted the contexts to my C:\Python27\Scripts file. However when I try:
根据自述文件 ( https://code.google.com/p/pytesser/wiki/README) 中的说明,我将上下文提取到我的 C:\Python27\Scripts 文件中。但是,当我尝试:
from pytesser import *
within the Python Shell, I get the following error:
在 Python Shell 中,我收到以下错误:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from pytesser import *
ImportError: No module named pytesser
Any ideas? Windows 7. Python 2.7. My other scripts using modules such as PIL, Scrapy, Numpy have been working fine.
有任何想法吗?Windows 7。Python 2.7。我使用 PIL、Scrapy、Numpy 等模块的其他脚本一直运行良好。
Thanks, Tom
谢谢,汤姆
采纳答案by wRAR
You should not use C:\Python27\Scriptsfor 3rd party modules, you should use C:\Python27\Lib\site-packagesinstead.
你不应该C:\Python27\Scripts用于 3rd 方模块,你应该使用它C:\Python27\Lib\site-packages。
回答by Samizdis
I suspect the problem is with Python not being able to find your C:\Python27\Scripts directory because it's not in your PYTHONPATH.
我怀疑问题在于 Python 无法找到您的 C:\Python27\Scripts 目录,因为它不在您的 PYTHONPATH 中。
Python looks in certain directories for files when you run an importcommand, they're described here http://docs.python.org/2/tutorial/modules.html#the-module-search-path
当您运行import命令时,Python 在某些目录中查找文件,它们在此处进行了描述http://docs.python.org/2/tutorial/modules.html#the-module-search-path
Your main options are:
您的主要选择是:
1) Tell Python to look in your Scripts folder. This involves adding the folder to your Python path, see here How to add to the pythonpath in windows 7?
1) 告诉 Python 查看您的 Scripts 文件夹。这涉及将文件夹添加到您的 Python 路径,请参阅此处如何添加到 Windows 7 中的 pythonpath?
2) Put your script in a folder which is already searched by Python. This is wRAR's answer, to use the standard Python 3rd-party modules directory, see here http://docs.python.org/2/install/index.html#how-installation-works
2) 将您的脚本放在 Python 已经搜索过的文件夹中。这是 wRAR 的答案,要使用标准的 Python 3rd-party modules 目录,请参见此处http://docs.python.org/2/install/index.html#how-installation-works
3) Have the pytesser file in Python's current directory. import osfollowed by os.getcwd()will show you python's current directory, where the code is running (in a sense). os.chdir("my/other/dir")changes the current directory. See How to know/change current directory in Python shell?for more detail.
3) 在 Python 的当前目录中有 pytesser 文件。import os其次是os.getcwd()将向您显示 python 的当前目录,代码在其中运行(在某种意义上)。os.chdir("my/other/dir")更改当前目录。请参阅如何知道/更改 Python shell 中的当前目录?了解更多详情。
回答by H2Ojile
You may got sth wrong. I try pytesser yesterday, maybe you should not put the pytesser file into the script folder. try the working dir, alongside with your code.
你可能搞错了。昨天试了一下pytesser,也许你不应该把pytesser文件放到脚本文件夹中。尝试工作目录以及您的代码。
>>> import pytesser
>>> print pytesser
<module 'pytesser' from 'E:\Desktop\jiaoben\OCR\pytesser.pyc'
回答by user2435950
回答by Yaitzme
I'm not sure if this is the ideal solution, but this works for me. Please do correct me if this is incorrect in any way.
我不确定这是否是理想的解决方案,但这对我有用。如果这在任何方面都不正确,请纠正我。
- Unzip the folder & paste it in your Python2x\Lib folder
- Rename it to pytesser (I'm not too sure if this is a necessary step)
- Duplicate the tesseract.py file and rename it as __init__.py
- Open __init__.py
- Change the line tesseract_exe_name = "tesseract" to tesseract_exe_name = 'C:\Python27\Lib\pytesser\tesseract'
- 解压缩文件夹并将其粘贴到您的 Python2x\Lib 文件夹中
- 将其重命名为 pytesser(我不太确定这是否是必要步骤)
- 复制 tesseract.py 文件并将其重命名为__init__.py
- 打开__init__.py
- 将 tesseract_exe_name = "tesseract" 更改为 tesseract_exe_name = 'C:\Python27\Lib\pytesser\tesseract'
Done.
完毕。
回答by Ross
Further to Yaitzme answer - another fix you may need (I'm using Python Tools for Visual Studio on Windows 7 64-bit)...
除了 Yaitzme 的答案 - 您可能需要的另一个修复程序(我在 Windows 7 64 位上使用 Python 工具用于 Visual Studio)...
Once I renamed the pytesser.py file to __init__ I had to put a double backslash in the line e.g.
将 pytesser.py 文件重命名为 __init__ 后,我必须在行中添加双反斜杠,例如
tesseract_exe_name = ‘C:\Anaconda2\Lib\site-packages\pytesser\\tesseract'
tesseract_exe_name = 'C:\Anaconda2\Lib\site-packages\pytesser\\tesseract'
as the single backslash '\tesseract' was interpreting the '\t' as a new tab symbol and breaking the path! Put my install instructions here
因为单个反斜杠 '\tesseract' 将 '\t' 解释为一个新的制表符并破坏了路径!把我的安装说明放在这里
回答by Peter
So I'm using w10 64 bits. And it took me some time to understand how you have to install it to be able to use it.
所以我使用 w10 64 位。我花了一些时间来了解您必须如何安装它才能使用它。
How to :
如何 :
https://code.google.com/archive/p/pytesser/downloads
https://code.google.com/archive/p/pytesser/downloads
download pytesser_v0.0.1.zip
下载 pytesser_v0.0.1.zip
unzip
解压
move files in the project
在项目中移动文件
rename import Image to "from PIL import Image" in the pytesser.py
在 pytesser.py 中将 import Image 重命名为“from PIL import Image”
=== Enjoy.
=== 享受。

