Python学习(三)

这里介绍自己在学历Python遇到的一个安装tesserocr的错误处理过程

1、环境:Python3.6,OS:win10 64操作系统

2、安装命令:pip3 install tesserocr pillow报错如下所示:

Exception:
Traceback (most recent call last):
  File "d:\python\python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 70: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\python\python36\lib\site-packages\pip\commands\install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "d:\python\python36\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "d:\python\python36\lib\site-packages\pip\req\req_set.py", line 634, in _prepare_file
    abstract_dist.prep_for_dist()
  File "d:\python\python36\lib\site-packages\pip\req\req_set.py", line 129, in prep_for_dist
    self.req_to_install.run_egg_info()
  File "d:\python\python36\lib\site-packages\pip\req\req_install.py", line 439, in run_egg_info
    command_desc='python setup.py egg_info')
  File "d:\python\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "d:\python\python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
    return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 70: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\python\python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "d:\python\python36\lib\site-packages\pip\commands\install.py", line 385, in run
    requirement_set.cleanup_files()
  File "d:\python\python36\lib\site-packages\pip\utils\build.py", line 38, in __exit__
    self.cleanup()
  File "d:\python\python36\lib\site-packages\pip\utils\build.py", line 42, in cleanup
    rmtree(self.name)
  File "d:\python\python36\lib\site-packages\pip\_vendor\retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "d:\python\python36\lib\site-packages\pip\_vendor\retrying.py", line 212, in call
    raise attempt.get()
  File "d:\python\python36\lib\site-packages\pip\_vendor\retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "d:\python\python36\lib\site-packages\pip\_vendor\six.py", line 686, in reraise
    raise value
  File "d:\python\python36\lib\site-packages\pip\_vendor\retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "d:\python\python36\lib\site-packages\pip\utils\__init__.py", line 102, in rmtree
    onerror=rmtree_errorhandler)
  File "d:\python\python36\lib\shutil.py", line 494, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "d:\python\python36\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "d:\python\python36\lib\shutil.py", line 393, in _rmtree_unsafe
    onerror(os.rmdir, path, sys.exc_info())
  File "d:\python\python36\lib\site-packages\pip\utils\__init__.py", line 114, in rmtree_errorhandler
    func(path)
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'C:\\Users\\jair\\AppData\\Local\\Temp\\pip-build-q4ms44lu\\tesserocr'

3、这里网上搜了一把参见:https://blog.csdn.net/qq_33530388/article/details/68933201。但是问题又来了。错误如下:

Collecting tesserocr
  Using cached https://files.pythonhosted.org/packages/cf/0d/9e554f041962b8dd7acd978330535fed879452bb0af257c287ca4ae9c525/tesserocr-2.2.2.tar.gz
Collecting pillow
  Downloading https://files.pythonhosted.org/packages/a4/86/283719dac6309cf483452abb09759be9b2c0974435ed608dc67949127e13/Pillow-5.1.0-cp36-cp36m-win_amd64.whl (1.6MB)
    100% |████████████████████████████████| 1.6MB 441kB/s
Installing collected packages: tesserocr, pillow
  Running setup.py install for tesserocr ... error
    Complete output from command d:\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\jair\\AppData\\Local\\Temp\\pip-build-bt09g9nm\\tesserocr\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\jair\AppData\Local\Temp\pip-ojqp2_rs-record\install-record.txt --single-version-externally-managed --compile:
    Failed to extract tesseract version from executable: [WinError 2] 系统找不到指定的文件。
    Supporting tesseract v3.04.00
    Building with configs: {'libraries': ['tesseract', 'lept'], 'cython_compile_time_env': {'TESSERACT_VERSION': 197632}}
    running install
    running build
    running build_ext
    building 'tesserocr' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    ----------------------------------------
Command "d:\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\jair\\AppData\\Local\\Temp\\pip-build-bt09g9nm\\tesserocr\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\jair\AppData\Local\Temp\pip-ojqp2_rs-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\jair\AppData\Local\Temp\pip-build-bt09g9nm\tesserocr\

4、我们看错误提示需要安装 Microsoft Visual C++ 14.0。那就来安装这个吧,软件下载路径:https://download.csdn.net/download/amoscn/10399046

5、解压安装重启系统

6、做完上面的步骤恭喜你能看到下面的错误了

Collecting tesserocr
  Using cached https://files.pythonhosted.org/packages/cf/0d/9e554f041962b8dd7acd978330535fed879452bb0af257c287ca4ae9c525/tesserocr-2.2.2.tar.gz
Collecting pillow
  Using cached https://files.pythonhosted.org/packages/a4/86/283719dac6309cf483452abb09759be9b2c0974435ed608dc67949127e13/Pillow-5.1.0-cp36-cp36m-win_amd64.whl
Installing collected packages: tesserocr, pillow
  Running setup.py install for tesserocr ... error
    Complete output from command d:\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\jair\\AppData\\Local\\Temp\\pip-build-hcaf24yd\\tesserocr\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\jair\AppData\Local\Temp\pip-it3yvefo-record\install-record.txt --single-version-externally-managed --compile:
    Failed to extract tesseract version from executable: [WinError 2] 系统找不到指定的文件。
    Supporting tesseract v3.04.00
    Building with configs: {'libraries': ['tesseract', 'lept'], 'cython_compile_time_env': {'TESSERACT_VERSION': 197632}}
    running install
    running build
    running build_ext
    building 'tesserocr' extension
    creating build
    creating build\temp.win-amd64-3.6
    creating build\temp.win-amd64-3.6\Release
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Id:\python\python36\include -Id:\python\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt" /EHsc /Tptesserocr.cpp /Fobuild\temp.win-amd64-3.6\Release\tesserocr.obj
    tesserocr.cpp
    tesserocr.cpp(596): fatal error C1083: Cannot open include file: 'leptonica/allheaders.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

    ----------------------------------------
Command "d:\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\jair\\AppData\\Local\\Temp\\pip-build-hcaf24yd\\tesserocr\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\jair\AppData\Local\Temp\pip-it3yvefo-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\jair\AppData\Local\Temp\pip-build-hcaf24yd\tesserocr\

7、网上又搜了一圈。解决方式参见:https://www.v2ex.com/t/438072

8、如果不按照第7步方式解决是否还有其他方式呢?自己记录一下,也希望大家讨论指正!


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011192409/article/details/80412625
文章标签: Python tesserocr
个人分类: Python
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭