You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装pytesseract后运行代码遇ModuleNotFoundError问题求助

解决ModuleNotFoundError: No module named 'pytesseract'问题

安装pytesseract模块后运行以下代码时,出现ModuleNotFoundError: No module named 'pytesseract'错误:

from PIL import Image
from pytesseract import pytesseract

# Define path to tessaract.exe
path_to_tesseract = r'C:\Python310\Scripts\pytesseract.exe'

# Define path to image
path_to_image = 'extract.png'

# Point tessaract_cmd to tessaract.exe
pytesseract.tesseract_cmd = path_to_tesseract

# Open image with PIL
img = Image.open(path_to_image)

# Extract text from image
text = pytesseract.image_to_string(img)

print(text)

解决步骤

  • 确保使用正确的安装命令:执行pip install pytesseract完成Python封装库的安装,注意pytesseract是Python模块,和底层的Tesseract OCR引擎是两个独立的东西,引擎需要单独安装,但当前报错为模块未找到,优先解决模块安装问题。
  • 匹配Python环境:如果系统存在多个Python版本,确认安装模块的pip和运行代码的Python是同一个环境:
    • 若运行代码用python script.py,则对应使用pip install pytesseract安装
    • 若用python3 script.py,则对应使用pip3 install pytesseract安装
    • 虚拟环境需先激活,再执行pip install pytesseract
  • 验证安装状态:在命令行执行pip show pytesseract,若能输出模块版本、安装路径等信息,说明安装成功;若提示找不到模块,重新执行安装命令,排查是否有网络或权限类报错。
  • 检查IDE解释器配置:如果用IDE(如VS Code、PyCharm)运行代码,需确认IDE选择的Python解释器是已经安装了pytesseract的那个环境。

内容的提问来源于stack exchange,提问作者Amira Mohamed Abdelsalam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 17:55:58