【问题标题】:Module missing while the module trying to import is already there尝试导入的模块已存在时模块丢失
【发布时间】:2017-09-02 20:36:47
【问题描述】:
from PIL import Image
from pytesser import *

image_file = 'E:\Downloads\menu.tiff'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print ("=====output=======\n")
print (text)

看到错误显示没有找到模块,但 util 文件在 tesseract 本身的目录中。我不知道为什么它会显示它没有找到。

我的问题非常简单,从 init.py 如何导入 util.py 和 errors.py

【问题讨论】:

    标签: python python-2.7 python-3.x python-tesseract


    【解决方案1】:

    您正在使用的图书馆似乎已超过六年没有被动过。它与 Python 3 不兼容。

    寻找另一个图书馆。

    【讨论】:

    • 我有一段时间没有编程了,我决定通过做一个图像到文本转换应用程序来学习 python。所以我对这个尝试了一切都意识到有一件事有一个 python 2.7 python 3+冲突正在进行。你能建议我任何替代方案吗?
    • 我真的不能,因为我不知道你想做什么。是什么促使您使用这个特定的晦涩模块?
    • 只有windows教程才有的东西。
    【解决方案2】:

    此包需要相对导入(请参阅PEP328)。

    解决办法是替换

    import util
    import errors
    

    通过

    from . import util
    from . import errors
    

    此更改是在 python 2.5(2006 年 9 月 19 日)中引入的,所以我完全同意 @DanielRoseman,您应该寻找另一个库。 例如,您可以在 PyPiGitHub 上找到 OCR 包。


    编辑:更正模块名称中的拼写错误

    【讨论】:

    • ------------------------------------------ --------------------------------- ImportError Traceback(最近一次调用最后)() 1 from PIL import Image ----> 2 from pytesser import * 3 4 image_file = 'E:\Downloads\menu.tiff' 5 im = Image.open(image_file) C:\Users\SACHIN \Anaconda3\lib\site-packages\pytesser_init_.py in () 7 import subprocess 8 ----> 9 from .导入 utils 10 从 .导入错误
    • 11 tesseract_exe_name = 'C:\\Users\\SACHIN\\Anaconda3\\Lib\\site-packages\\pytesser\\tesseract' # 在命令行调用的可执行文件名 ImportError:无法导入名称“utils”
    • 兄弟都给出了这个错误我已经尝试过你的解决方案。我被困在做什么
    • 好吧,我这边看起来像是一个错字:utils 应该是 util。编辑答案。仍然以这种方式得到 same 错误?
    • 该错误已更改,但问题是必须纠正所有底层模块现在这是错误,完成此操作后将不再有错误文件“C:\Users\SACHIN\ Anaconda3\lib\site-packages\pytesser\errors.py",第 15 行将 Tesser_General_Exception 作为文本引发 ^ SyntaxError: invalid syntax
    猜你喜欢
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 2010-11-11
    • 2023-01-08
    • 1970-01-01
    相关资源
    最近更新 更多