可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
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:
from pytesser import *
within the Python Shell, I get the following error:
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.
Thanks,
Tom
回答1:
You should not use C:\Python27\Scripts
for 3rd party modules, you should use C:\Python27\Lib\site-packages
instead.
回答2:
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'
Done.
回答3:
I managed to get it working according to the instructions on this site.
I just used Google's translate to turn the text into English!
Hope this helps!
:)
回答4:
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.
How to :
https://code.google.com/archive/p/pytesser/downloads
download pytesser_v0.0.1.zip
unzip
move files in the project
rename import Image to "from PIL import Image" in the pytesser.py
=== Enjoy.
回答5:
Further to Yaitzme answer - another fix you may need (I'm using Python Tools for Visual Studio on Windows 7 64-bit)...
Once I renamed the pytesser.py file to __init__ I had to put a double backslash in the line e.g.
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
回答6:
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 looks in certain directories for files when you run an import
command, they're described here 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?
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
3) Have the pytesser file in Python's current directory. import os
followed 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.
回答7:
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.
>>> import pytesser
>>> print pytesser
<module 'pytesser' from 'E:\Desktop\jiaoben\OCR\pytesser.pyc'