首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FileNotFoundError:[WinError 2]使用pytesseract python-3.x时,系统找不到指定的文件

FileNotFoundError:[WinError 2]使用pytesseract python-3.x时,系统找不到指定的文件
EN

Stack Overflow用户
提问于 2016-07-25 02:33:06
回答 1查看 1.4K关注 0票数 0

我正在使用pytesseract在python中将图像读取为文本。以下是我的代码:

代码语言:javascript
复制
from PIL import Image
from pytesseract import image_to_string
import os.path

if (os.path.exists('image.png')):
    filename = 'image.png'
    image = Image.open(filename)
    image.show()
    s = image_to_string(Image.open(filename))
else:
    print('Does not exist')

代码获取文件image.png,将其打开并向我显示图像,这意味着该文件存在于该目录中。但是当它转到下一行s = image_to_string(Image.open(filename))时,它会给出以下错误。

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:/Users/hp/Desktop/GII/Genetic_Algorithm.py", line 8, in <module>
    s = image_to_string(Image.open(filename))
  File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
    config=config)
  File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
    stderr=subprocess.PIPE)
  File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

我努力了,但不知道该如何处理。

EN

回答 1

Stack Overflow用户

发布于 2016-07-25 02:48:38

也许可以试试:

f2 =os.path.abspath(文件名)

S= image_to_string(Image.open(f2))

显然,PIL正在使用一些子进程,这些子进程可能与主进程具有不同的“默认目录”

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38555408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档