Python3.6安装tesserocr遇到的问题

1、安装tesserocr报错

pip3 install tesserocr pillow

报错

ERROR: Command errored out with exit status 1:
     command: d:\programfiles\development\python\python36\python.exe -c import sys,setuptools,tokenize; sys.argv[0] = ‘""‘C:\\Users\\hasee\\AppData\\Local\\Temp\\pip-install-4nbm_b4s\\tesserocr\\setup.py‘""‘; __file__=‘""‘C:\\Users\\hasee\\AppData\\Local\\Temp\\pip-install-4nbm_b4s\\tesserocr\\setup.py‘""‘;f=getattr(tokenize,‘""‘open‘""‘,open)(__file__);code=f.read().replace(‘""‘\r\n‘""‘,‘""‘\n‘""‘);f.close();exec(compile(code,__file__,‘""‘exec‘""‘)) egg_info --egg-base pip-egg-info
         cwd: C:\Users\hasee\AppData\Local\Temp\pip-install-4nbm_b4s\tesserocr    Complete output (165 lines):
    Supporting tesseract v3.05.01
    Building with configs: {libraries: [tesseract,lept],cython_compile_time_env: {TESSERACT_VERSION: 50659584}}
    Compiling C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Plex\Scanners.py because it changed.
    Compiling C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Plex\Actions.py because it changed.
    Compiling C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Compiler\Scanning.py because it changed.
    Compiling C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Compiler\Visitor.py because it changed.
    Compiling C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Compiler\FlowControl.py because it changed.
    Compiling C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Runtime\refnanny.pyx because it changed.
    Compiling C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Compiler\Fusednode.py because it changed.
    Compiling C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Tempita\_tempita.py because it changed.
    [1/8] Cythonizing C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Compiler\FlowControl.py
    [2/8] Cythonizing C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Compiler\Fusednode.py
    [3/8] Cythonizing C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Compiler\Scanning.py
    [4/8] Cythonizing C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Compiler\Visitor.py
    [5/8] Cythonizing C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Plex\Actions.py
    [6/8] Cythonizing C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Plex\Scanners.py
    [7/8] Cythonizing C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Runtime\refnanny.pyx
    [8/8] Cythonizing C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\Cython\Tempita\_tempita.py
    Unable to find pgen,not compiling formal grammar.
    warning: no files found matching Doc\*
    warning: no files found matching *.pyx under directory Cython\Debugger\Tests
    warning: no files found matching *.pxd under directory Cython\Debugger\Tests
    warning: no files found matching *.pxd under directory Cython\Utility
    warning: no files found matching pyximport\README
    Traceback (most recent call last):
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\msvc.py",line 477,in __init__
        self.vc_ver = self.find_available_vc_vers()[-1]
    IndexError: list index out of range

    During handling of the above exception,another exception occurred:

    Traceback (most recent call last):
      File "d:\programfiles\development\python\python36\lib\distutils\core.py",line 148,in setup
        dist.run_commands()
      File "d:\programfiles\development\python\python36\lib\distutils\dist.py",line 955,in run_commands
        self.run_command(cmd)
      File "d:\programfiles\development\python\python36\lib\distutils\dist.py",line 974,in run_command
        cmd_obj.run()
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\bdist_egg.py",line 161,in run
        cmd = self.call_command(install_lib,warn_dir=0)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\bdist_egg.py",line 147,in call_command
        self.run_command(cmdname)
      File "d:\programfiles\development\python\python36\lib\distutils\cmd.py",line 313,in run_command
        self.distribution.run_command(command)
      File "d:\programfiles\development\python\python36\lib\distutils\dist.py",in run_command
        cmd_obj.run()
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\install_lib.py",line 11,in run
        self.build()
      File "d:\programfiles\development\python\python36\lib\distutils\command\install_lib.py",line 107,in build
        self.run_command(build_ext)
      File "d:\programfiles\development\python\python36\lib\distutils\cmd.py",in run_command
        cmd_obj.run()
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\build_ext.py",line 75,in run
        _build_ext.run(self)
      File "d:\programfiles\development\python\python36\lib\distutils\command\build_ext.py",line 339,in run
        self.build_extensions()
      File "d:\programfiles\development\python\python36\lib\distutils\command\build_ext.py",line 448,in build_extensions
        self._build_extensions_serial()
      File "d:\programfiles\development\python\python36\lib\distutils\command\build_ext.py",line 473,in _build_extensions_serial
        self.build_extension(ext)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\build_ext.py",line 196,in build_extension
        _build_ext.build_extension(self,ext)
      File "d:\programfiles\development\python\python36\lib\distutils\command\build_ext.py",line 533,in build_extension
        depends=ext.depends)
      File "d:\programfiles\development\python\python36\lib\distutils\_msvccompiler.py",line 304,in compile
        self.initialize()
      File "d:\programfiles\development\python\python36\lib\distutils\_msvccompiler.py",line 197,in initialize
        vc_env = _get_vc_env(plat_spec)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\msvc.py",line 172,in msvc14_get_vc_env
        return EnvironmentInfo(plat_spec,vc_min_ver=14.0).return_env()
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\msvc.py",line 771,in __init__
        self.si = SystemInfo(self.ri,vc_ver)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\msvc.py",line 480,in __init__
        raise distutils.errors.distutilsPlatformError(err)
    distutils.errors.distutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    During handling of the above exception,another exception occurred:

    Traceback (most recent call last):
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",line 157,in save_modules
        yield saved
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",line 198,in setup_context
        yield
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",line 248,in run_setup
        DirectorySandBox(setup_dir).run(runner)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",line 278,in run
        return func()
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",line 246,in runner
        _execfile(setup_script,ns)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",line 47,in _execfile
        exec(code,globals,locals)
      File "C:\Users\hasee\AppData\Local\Temp\easy_install-a2pfd_p3\Cython-0.29.13\setup.py",line 285,in <module>
      File "d:\programfiles\development\python\python36\lib\distutils\core.py",line 163,in setup
        raise SystemExit("error: " + str(msg))
    SystemExit: error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    During handling of the above exception,another exception occurred:

    Traceback (most recent call last):
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\easy_install.py",line 1101,in run_setup
        run_setup(setup_script,args)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",line 251,in run_setup
        raise
      File "d:\programfiles\development\python\python36\lib\contextlib.py",line 100,in __exit__
        self.gen.throw(type,value,traceback)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",in setup_context
        yield
      File "d:\programfiles\development\python\python36\lib\contextlib.py",line 169,in save_modules
        saved_exc.resume()
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",line 144,in resume
        six.reraise(type,exc,self._tb)
      File "d:\programfiles\development\python\python36\lib\site-packages\pkg_resources\_vendor\six.py",line 685,in reraise
        raise value.with_traceback(tb)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\sandBox.py",another exception occurred:

    Traceback (most recent call last):
      File "<string>",line 1,in <module>
      File "C:\Users\hasee\AppData\Local\Temp\pip-install-4nbm_b4s\tesserocr\setup.py",line 210,in <module>
        setup_requires=[Cython>=0.23],File "d:\programfiles\development\python\python36\lib\distutils\core.py",line 108,in setup
        _setup_distribution = dist = klass(attrs)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\dist.py",line 315,in __init__
        self.fetch_build_eggs(attrs[setup_requires])
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\dist.py",line 361,in fetch_build_eggs
        replace_conflicting=True,File "d:\programfiles\development\python\python36\lib\site-packages\pkg_resources\__init__.py",line 850,in resolve
        dist = best[req.key] = env.best_match(req,ws,installer)
      File "d:\programfiles\development\python\python36\lib\site-packages\pkg_resources\__init__.py",line 1122,in best_match
        return self.obtain(req,line 1134,in obtain
        return installer(requirement)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\dist.py",line 429,in fetch_build_egg
        return cmd.easy_install(req)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\easy_install.py",line 665,in easy_install
        return self.install_item(spec,dist.location,tmpdir,deps)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\easy_install.py",line 695,in install_item
        dists = self.install_eggs(spec,download,tmpdir)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\easy_install.py",line 876,in install_eggs
        return self.build_and_install(setup_script,setup_base)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\easy_install.py",line 1115,in build_and_install
        self.run_setup(setup_script,setup_base,args)
      File "d:\programfiles\development\python\python36\lib\site-packages\setuptools\command\easy_install.py",line 1103,in run_setup
        raise distutilsError("Setup script exited with %s" % (v.args[0],))
    distutils.errors.distutilsError: Setup script exited with error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

解决方法

先查看pip支持的版本

C:\Users\hasee>python
Python 3.6.1 (v3.6.1:69c0db5,Mar 21 2017,17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help","copyright","credits" or "license" for more information.
>>> import pip
>>> import pip._internal
>>> print(pip._internal.pep425tags.get_supported())
[(cp36,cp36m,win32),(cp36,none,(py3,any),(cp3,(py36,(py35,(py34,(py33,(py32,(py31,(py30,any)]
>>> exit()

在https://github.com/simonflueckiger/tesserocr-windows_build/releases这里下载对应pip版本的tesserocr,然后安装

D:\ProgramFiles\Development\Python>pip3 install tesserocr-2.4.0-cp36-cp36m-win32.whl
Processing d:\programfiles\development\python\tesserocr-2.4.0-cp36-cp36m-win32.whl
Installing collected packages: tesserocr
Successfully installed tesserocr-2.4.0

 

2、导入PIL报没有模块

D:\ProgramFiles\Development\Python>python
Python 3.6.1 (v3.6.1:69c0db5,"credits" or "license" for more information.
>>> import tesserocr
>>> from PIL import Image
Traceback (most recent call last):
  File "<stdin>",in <module>
ModuleNotFoundError: No module named PIL

解决方法

在https://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow这个网站上下载对应pip版本的pillow,然后安装

D:\ProgramFiles\Development\InternetWrom\download>pip install Pillow-6.1.0-cp36-cp36m-win32.whl
Processing d:\programfiles\development\internetwrom\download\pillow-6.1.0-cp36-cp36m-win32.whl
Installing collected packages: Pillow
Successfully installed Pillow-6.1.0

测试

D:\ProgramFiles\Development\InternetWrom\Test>python
Python 3.6.1 (v3.6.1:69c0db5,"credits" or "license" for more information.
>>> import tesserocr
>>> from PIL import Image

 

3、RuntimeError: Failed to init API,possibly an invalid tessdata path:

C:\Users\hasee>python
Python 3.6.1 (v3.6.1:69c0db5,"credits" or "license" for more information.
>>> import tesserocr
>>> from PIL import Image
>>> img = Image.open(D:\ProgramFiles\Development\InternetWrom\Test\image.png)
>>> print(tesserocr.image_to_text(img))
Traceback (most recent call last):
  File "<stdin>",in <module>
  File "tesserocr.pyx",line 2443,in tesserocr._tesserocr.image_to_text
RuntimeError: Failed to init API,possibly an invalid tessdata path: D:\ProgramFiles\Development\Python\python36\Scripts/

解决方法

Path中添加 D:\ProgramFiles\Development\InternetWrom\Tesseract-OCR\Tesseract-OCR

新建变量名--TESSDATA_PREFIX 
变量值--D:\ProgramFiles\Development\InternetWrom\Tesseract-OCR\tessdata

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...