我曾经遇到过类似的错误。因此,我希望能够帮助那些遇到这类问题的人。
在我的情况下,
我尝试在树莓派3上使用pytesseract库运行Python代码。
$ pip install pillow
$ pip install pytesseract
(跟随 https://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/)
然后,我创建了一个 example.py 文件进行测试。
example.py
try:
import Image
except ImportError:
from PIL import Image
from pytesseract import *
print(pytesseract.image_to_string(Image.open('YOUR_IMAGE_PATH')))
然后,当我运行这段代码时,像你一样,我得到了以下错误。
ImportError: No module named pytesseract
在看了@Bertrand Caron的答案之后,我找到了解决方案。我的问题是软件包库路径。
我也安装了多个Python版本,2.7和3.5,就像作者一样。
当我在Linux上运行命令$python --version
时,结果是Python 2.7.13。
在我的情况下,当我安装pytesseract软件包时,
它被存储在"/usr/local/lib/python3.5/dist-packages/pytesseract"中。
当我运行$python -v example.py
时,我发现所引用的软件包路径与上面的pytesseract软件包目录不同。
参见。
已安装的pytesseract路径:/usr/local/lib/python3.5/dist-packages/pytesseract
实际引用的库路径,在运行时:/usr/lib/python2.7/dist-packages/
因此,我将位于"/usr/local/lib/python3.5/dist-packages/pytesseract"的pytesseract复制到"/usr/lib/python2.7/dist-packages/"中
然后,问题解决了!
pip install -r requirements.txt
吗? 这会根据requirement.txt
文件中的内容安装所有所需的包,如此问题所述。 - Bertrand Caroncli.py
和pytesseract
是相对于两个不同的版本进行安装的。解决方案:在你运行脚本的版本下安装pytesseract
,或者使用含有pytesseract
的版本运行脚本。 - Two-Bit Alchemistpip install pytesseract
。 - Bogdan Daniel