python上的FileNotFoundError
我想读取图像,以便将其转换为文本,但出现错误系统无法找到指定的文件。我认为这和python的工作目录有关。如果这是一个愚蠢的问题,我很抱歉,但我希望你能帮助我 这是mssg的完全错误python上的FileNotFoundError,python,python-3.x,Python,Python 3.x,我想读取图像,以便将其转换为文本,但出现错误系统无法找到指定的文件。我认为这和python的工作目录有关。如果这是一个愚蠢的问题,我很抱歉,但我希望你能帮助我 这是mssg的完全错误 img = printscreen_pil img = img.filter(ImageFilter.MedianFilter()) enhancer = ImageEnhance.Contrast(img) img = enhancer.enhance(2) img = img.convert('1') img.
img = printscreen_pil
img = img.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(2)
img = img.convert('1')
img.save('temp.jpg')
text = pytesseract.image_to_string(Image.open('temp.jpg'))
回溯(最近一次呼叫最后一次):
文件“C:\Users\pncor\Documents\pyprograms\bot.py”,第23行,在
text=pytesseract.image_to_字符串(image.open('temp.jpg'))
文件“C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\site packages\pytesseract\pytesseract.py”,第122行,位于图像\u到\u字符串中
config=config)
文件“C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\site packages\pytesseract\pytesseract.py”,第46行,运行\u tesseract
proc=subprocess.Popen(命令,stderr=subprocess.PIPE)
文件“C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py”,第707行,在uu init中__
恢复信号,启动新会话)
文件“C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py”,第990行,在\u execute\u child中
startupinfo)
FileNotFoundError:[WinError 2]系统找不到指定的文件
该软件包似乎未安装在您的系统上,或者在您的路径上找不到pytesseract
将tesseract
二进制文件作为子进程运行,以执行OCR
使用操作系统上的软件包管理器进行安装,或参阅。您正在使用Windows,请检查
此外,我认为没有必要先将增强图像写入文件,只需将其直接传递给pytesseract.image\u to\u string
:
Traceback (most recent call last):
File "C:\Users\pncor\Documents\pyprograms\bot.py", line 23, in <module>
text = pytesseract.image_to_string(Image.open('temp.jpg'))
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\pncor\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
图像和脚本应该在同一个目录下…错误很明显;检查您的图片是否与python脚本位于同一目录,因为您引用了它。如果您可以发布完整的错误并指出导致错误的行,则帮助会更容易。我猜是“img.convert('1')”行触发了错误,因为它找不到名为“1”的文件。也许它实际上是“1.jpg”之类的?但我只是猜测,没有足够的信息。我将脚本保存在图像的同一目录tho://@PNC:确认您已在系统上实际安装了
tesseract
,并且它位于您的路径上。有关详细信息,请参阅。
text = pytesseract.image_to_string(img)