3

Sorry, complete newbie question here.....I installed tesseract, tesseract-lang both via homebrew, also via the terminal (using conda install https://anaconda.org/conda-forge/tesseract ). In the terminal it looks like it is installed as I get this message when I try to reinstall it;

 ~ % conda install -c conda-forge tesseract
Collecting package metadata (current_repodata.json): done
Solving environment: done

All requested packages already installed.

However, when I run this code;

from PIL import Image
import pytesseract 
import numpy as np

filename = 'example_image_01.png'
img1 = np.array(Image.open(filename))
text = pytesseract.image_to_string(img1)

print(text)

Anaconda returns;
ModuleNotFoundError: No module named 'pytesseract'

I have also tried it with just tesseract but to no avail.

Anyone have any suggestions given I am relatively inexperienced as I am still learning python.

Thanks, Trevor

T-RevLey
  • 31
  • 2

1 Answers1

0

The packages tesseract and pytesseract are distinct. The latter is what provides Python bindings for interacting with the former. That is, you need to install both packages to use the latter:

conda install -c conda-forge pytesseract tesseract

Technically, if one already has tesseract installed on the system-level, then it should not need to be separately installed in the Conda environment. However, some may regard it as better practice to include everything needed to replicate a project in the Conda environment.

merv
  • 67,214
  • 13
  • 180
  • 245
  • Thanks for coming back on this. When I use this command (thank you for mentioning the better practice) in the terminal it returns this; – T-RevLey Mar 04 '21 at 14:32
  • % conda install -c conda-forge pytesseract tesseract Collecting package metadata (current_repodata.json): done Solving environment: done # All requested packages already installed. – T-RevLey Mar 04 '21 at 14:56
  • I can see it in the terminal but not in VSCode or Spyder even after this conda install command. Also, thank you for helping @Merv I am very grateful. – T-RevLey Mar 04 '21 at 14:57
  • @T-RevLey make sure you are executing the Python code in the Anaconda environment. – merv Mar 05 '21 at 01:23
  • Thanks, @Merv took a bit of time but figured out what you meant (that's because I'm a complete novice) but I got it when I moved from where it was installed into the right directory. Thank you for taking the time to help me out. – T-RevLey Mar 05 '21 at 16:36
  • 1
    @T-RevLey it's not about directories - it's about [activating the Conda environment](https://conda.io/projects/continuumio-conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment). I'd recommend working through Conda documentation. – merv Mar 05 '21 at 16:55
  • 1
    Ah got it. Working through environments now, thank you again for all the assistance – T-RevLey Mar 08 '21 at 10:11