ImportError: No module named pytesseract

后端 未结 4 1563
我寻月下人不归
我寻月下人不归 2021-01-07 05:50

I was following this guide https://realpython.com/blog/python/setting-up-a-simple-ocr-server/ and got to the part where I run cli.py python flask_server/cli.py

相关标签:
4条回答
  • 2021-01-07 06:31

    In my case, I was running it in Jupyter so I used this command,

    ! pip install --user pytesseract
    

    But I forgot to restart the kernal. You need to restart the kernal after installing the pakcage

    0 讨论(0)
  • 2021-01-07 06:45

    Python import errors usually boils down to one of those three cases (whether is is modules you developed; or modules distributed as packages):

    1. You did no install the required package. Googling pytesseracttells me its an OCR that is distributed and installable using Python package manager tool pip by running pip install pytesseract in your favorite shell.

    2. You did install the package, but is is not in your python path.

    3. (Less often) You did install the package, and it is in your python path, but you used a name already in user by Python, and the two are conflicting.

    In your case, I strongly think this is the first one. Case 2. and 3. can be assessed by calling python -v your_script.pyas described in this answer.

    0 讨论(0)
  • 2021-01-07 06:47

    I had the same error. My solution is

    $ pip3 install pytesseract
    

    since I have python 2 and python 3 installed together.

    0 讨论(0)
  • 2021-01-07 06:51

    I had a similar error. So I hope to help people with this kind of problems.

    In my case, I tried to run python code using pytesseract lib on Raspberry pi 3.

    $ pip install pillow
    $ pip install pytesseract
    

    (followed by https://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/)


    and then, I made an example.py to test.

    example.py

    try:
    
        import Image
    
    except ImportError:
    
        from PIL import Image
    
    from pytesseract import *
    
    print(pytesseract.image_to_string(Image.open('YOUR_IMAGE_PATH')))
    

    and then, when I run this code, I got below error like you. ImportError: No module named pytesseract


    After I saw the @Bertrand Caron's answer, I found a solution. My problem was package library path.

    I also have multiple versions of python, 2.7 and 3.5, like a writer. When I run command $python --version on linux, the result is Python 2.7.13.

    In my case, when I installed a pytesseract package, it was stored in "/usr/local/lib/python3.5/dist-packages/pytesseract".

    And When I ran $python -v example.py, I found the referenced packages path hadn't been same with upper pytesseract package directory.

    cf.

    installed pytesseract path : /usr/local/lib/python3.5/dist-packages/pytesseract

    actual referenced lib path, when running : /usr/lib/python2.7/dist-packages/

    So, I copied pytesseract, located in "/usr/local/lib/python3.5/dist-packages/pytesseract" to "/usr/lib/python2.7/dist-packages/"

    Then, Solved!

    0 讨论(0)
提交回复
热议问题