我在Spyder | Anaconda自定义(64位)中使用Windows 7,64位和Python 3.6.4。
Python的安装文件夹:
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Anaconda3_64\\pythonw.exe"
我按照此stackoverflow链接安装了软件包:
" How to install tesserocr on windows?"
首先,我在anaconda中尝试了这个命令:
conda create -n OCR python=3.6
activate OCR
conda install -c simonflueckiger tesserocr
上面的命令运行没有任何错误,但当我打开我的spyder并输入:
import tesserocr
它没有用,并说ModuleNotFoundError: No module named 'tesserocr'
其次我尝试使用.whl文件..,它安装完美,导入工作正常。但是,当我运行以下代码时:
import tesserocr
from PIL import Image
print (tesserocr.tesseract_version() ) # print tesseract-ocr version
print (tesserocr.get_languages() ) # prints tessdata path and list of
available languages
image = Image.open('C:\\Users\\hack\\Desktop\\Steve.jpeg')
print(image)
print (tesserocr.image_to_text(image) ) # print ocr text from image
它发出了一条消息:
tesseract 4.00.00alpha
leptonica-1.75.3 (Mar 24 2018, 15:42:29) [MSC v.1900 LIB Release x64]
libgif 5.1.4 : libjpeg 9b : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 :
libwebp 0.6.1 : libopenjp2 2.3.0
ocr和语言的路径:
('C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\', [])
错误:
File "C:\Program Files (x86)\Microsoft Visual
Studio \ Shared \ Anaconda3_64 \ lib \ sitepackages \ spyder \ utils \ site \ sitecustomize.py",第705行,在runfile中 execfile(filename,namespace)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/hack/Desktop/OCR.py", line 26, in <module>
print (tesserocr.image_to_text(image) ) # print ocr text from image
File "tesserocr.pyx", line 2401, in tesserocr._tesserocr.image_to_text
RuntimeError: Failed to init API, possibly an invalid tessdata path: C:\Program Files (x86)\Microsoft Visual Studio\Shared\
答案 0 :(得分:0)
嘿,我知道它已经很晚了,希望你已经解决了它,但你需要将tessdata文件夹复制到你的python路径所在的地方