PyTesseract not working - python

After installing PyTesseract, I went into my Mac's terminal to make sure it works. I got it to output into a text file perfectly find, but after running this code in Enthought Canopy:
import pytesseract
from PIL import Image
print pytesseract.image_to_string(Image.open('/Users/Nelson/Desktop/Projects/R6S Statistics/OCR/ocr-test.png'))
I get this:
AttributeError: 'ImagingDecoder' object has no attribute 'pulls_fd'
This error comes from the PIL file:
/Users/Nelson/Desktop/Canopy/User/lib/python2.7/site-packages/PIL/ImageFile.pyc

I was able to resolve this error by restarting my Jupyter notebook kernel. I performed a pip install --upgrade scikit-image in the middle of a notebook session and got this error. The upgrade installed a newer version of PIL (v4.0) but the previously installed (v3.2) version has already been loaded into memory.

Related

Tensorflow import error when loading PIL (pillow)

I'm having an issue with my tensorflow on windows 10 (python 3.7, tf 2.1.0, keras 2.3.1, pillow 7.1.1). I had some code I wrote on an osx machine and was porting over to windows. I am using conda envs and have all the necessary packages installed (tensorflow, keras, pillow, opencv, etc) but I am getting the following error
Traceback (most recent call last):
...
"...\venv\lib\site-packages\keras_preprocessing\image\utils.py", line 108, in load_img
raise ImportError('Could not import PIL.Image. '
ImportError: Could not import PIL.Image. The use of `load_img` requires PIL.
I have tried reinstalling pillow, tensorflow, keras, creating a new environment, installing with pip and repeated this in about every location I can think of but this issue remains persistent. Any help would be greatly appreciated.
Thank you
One solution that might work for your case:
First, you need to : pip install pillow (uninstall + reinstall / upgrade it it's the case)
Second, you need to change your imports in this way:
from IPython.display import display
from PIL import Image
This solution can be found in the following thread:
ImportError: Could not import the Python Imaging Library (PIL) required to load image files on tensorflow

open a .jpg image in python using matplotlib.image in python 3.6

I am trying to open a JPG image using matplotlib in Python. Editor 'Spyder', Python3.6, WIndows 7
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
# Read in the image and print some stats
image = mpimg.imread(r'C:\Users\xxx\Python Code\mountain.jpg')
print('This image is: ',type(image),
'with dimensions:', image.shape)
But I am getting the following error... It says that except '.png' no other image format is supported.
Error :--
image = mpimg.imread(r'C:\Users\xxx\Python Code\mountain.jpg')
File "C:\temp\Continuum\anaconda3\lib\site-packages\matplotlib\image.py",
line 1284, in imread
'more images' % list(handlers))
ValueError: Only know how to handle extensions: ['png']; with Pillow
installed matplotlib can handle more images.
I went through various documentations. Which says that, in order to open a '.jpg' image, 'Pillow' must be installed.
If native matplotlib call fails to open a image then it automatically falls back on 'pillow'. (correct me if I am wrong)
So I installed 'Pillow'. But I am still getting the error.
Can you tell me what am I Missing ? (Strange thing is this same code is running in another computer. I have no way to verify what library is installed in that machine)
Matplotlib requires PIL(Python Imaging Library) to work with .jpg format. To use it you need to install Pillow (which is the fork of PIL).
Installation Using PIP
pip install pillow
or
pip3 install pillow
Installation Using Conda
conda install pillow
You have to install PIL. Make sure you are using anaconda python distro. Go to this link or write this command to install PIL directly
conda install -c anaconda pillow

No module named pytesseract error

I am trying to use pytesseract for OCR, on a raspberry pi using Raspbian
I have read several questions on this topic, but can't find an answer that works, they usually say to install pytesseract with pip, and I did it.
my code is very simple:
import pytesseract
from PIL import Image
print(pytesseract.image_to_string(Image.open('test.jpg')))
But it returns error message : "ImportError: No module named 'pytesseract' .
I have installed tesseracrt-ocr (the whereis tesseract-ocr command returns /usr/share/tesseract-ocr)
I have installed pytesseract with pip install tesseract (which returns successfully installed Pillow-4.3.0 olefile-0.44 pytesseract-0.1.7 ... but the whereis pytesseract command does not return anything --> a problem?).
Do you have any idea of the problem I have ?
See after installing pytesseract ,using
<cmd>C:\> pip install pytesseract
Try :
import pytesseract
If above is not working then it has do something with the installation ,
Check if pytesseract folder is available under "\Python27\Lib\site-packages" ,
Try the above command from site packages, Hope this helps ,
Else there is something wrong with installation .
Add this line in your code
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
set your path where tesseract-ocr is installed and also add this path to your window environment variable.Also check this link Tesseract installation for complete installation of tesseract.

I am using Pillow and getting an error "ImportError :No module named Image" in Ubuntu?

Does anyone know why I am getting this error?
I have Ubuntu 32-Bit , and Python 32-Bit and Installed Pillow using pip
Here is the code:
import Image
import pytesseract
print pytesseract.image_to_string(Image.open('1.jpg'))
Here is the error :
Traceback (most recent call last):
File "/home/siamak/workspace/test/com/tower/test/ocr.py", line 1, in
import Image
ImportError: No module named Image
You have to do:
from PIL import Image
Image is a submodule of PIL, so you have to use the from...import syntax.
I tested it on Linux Mint , and CentOS and it works perfectly .
For some reason it doesn't work on Ubuntu 32 and 64 .
I am assuming it is related to the PIL installation
Thanks
I also had this problem where,
from PIL import Image
gave this same error as the one in your comment:
from PIL import _imaging as core
ImportError: /home/jer/.local/lib/python2.7/site-packages/PIL/_imaging.so:
undefined symbol: PyUnicodeUCS4_AsLatin1String
It seems a locally installed version of Pillow is the culprit. We can uninstall the local version with,
pip uninstall Pillow
This left the system version of Pillow installed, which worked fine.

Pillow import error from _imaging.so / libjpeg.8.dylib on OSX

I've used Pillow in the past on OSX without problems, however I now get the following error.
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 61, in <module>
from PIL import _imaging as core
ImportError: dlopen(/Library/Python/2.7/site-packages/PIL/_imaging.so, 2): Library not loaded: /usr/local/lib/libjpeg.8.dylib
Referenced from: /Library/Python/2.7/site-packages/PIL/_imaging.so
Reason: image not found
I've seen this question which appears to be a similar problem but I don't think I installed Pillow with brew.
I've also tried the solution from this question but the command
pip install PIL --allow-external PIL --allow-unverified PIL
dosent seem to work and I get an error (no such option: --allow-unverified)
Lastly, I've tried to recreate the symbolic link to libjpeg.8.dylib but that also did not make any difference.
Would anyone know how to fix this error? Do I need to do something to relink _image.so aswell as libjpeg?
Python PIL was deprecated eons ago and you should not attempt to use it anymore.
What you want is python[23] -m pip install Pillow
PS. Using pip command will be deprecated soon because of confusions regarding python interpreters, instead of calling pip ... everyone should use only python -m pip ... which assures that is calling the right interpreter.

Categories

Resources