0

i am currently trying to use Pytesseract via VSCode.

try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('/users/lucas/desktop/image.png')))

This code doesn't work, it tells me " from PIL import Image ModuleNotFoundError: No module named 'PIL'". The website I'm using that explains how to use it (in French here) tells me that if I cannot launch this code, I need to put that

    
<pre class="wp-block-syntaxhighlighter-code">pytesseract.pytesseract.tesseract_cmd = r'<Chemin complet pour lancer l exécutable en ligne de commande>'</pre>

to the terminal. Which I did, so I put

<pre class="wp-block-syntaxhighlighter-code">pytesseract.pytesseract.tesseract_cmd = r'/users/lucas/tessdata-main'</pre>

in my terminal. But it gives me the "zsh: parse error near `\n'" error.

Does anyone have a solution to my problem please ?

Changing ' with ", getting the <pre.... out, putting the sentence in the code instead of the terminal, putting the tessdata-main in a folder on my desktop to change the path to my desktop.

  • Hello, I think your problem is the same as this one https://stackoverflow.com/questions/8863917/importerror-no-module-named-pil – Paul Jul 07 '23 at 13:37
  • I tried to install "pillow" as they said but still doesn't work. The "image" thing that the 2nd best comment says is already in my code as you can see, so not working either. – Lucas Roblin Jul 07 '23 at 15:01
  • Strange, maybe the try catch is not working as expected, try to only keep the `import Image` and not the rest ? – Paul Jul 10 '23 at 13:24
  • Just tried it, and I got the error "ModuleNotFoundError: No module named 'Image'". So the problem comes from Vscode finding Tesseract, which I have no idea how to resolve – Lucas Roblin Jul 11 '23 at 07:31
  • The error says that it canno't find the Image module, so it's not about tesseract yet. Did you run `pip install Pillow` and `pip install image` in the terminal ? – Paul Jul 11 '23 at 07:40

1 Answers1

0

Okay so in the end I had to install the same version as my python version. Seems like I have 2 different versions of Python on my computer, so I did a "python3 -version" and then downloaded the exact version with I don't remember which command.

  • Hey there! Did you use `python3 -m pip install SOMEPACKAGE==VERSION` to install the version you needed? Or just using `python3` was enough? – Pedram Jul 23 '23 at 18:48