0

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

wpercy
  • 9,636
  • 4
  • 33
  • 45

3 Answers3

0

You have to do:

from PIL import Image

Image is a submodule of PIL, so you have to use the from...import syntax.

  • I tried now it says : from PIL import _imaging as core .I changed it to core and doesn't work – Siamak Heshmati Feb 17 '16 at 23:20
  • @SiamakHeshmati Could you provide the full error message? –  Feb 17 '16 at 23:21
  • here is the full error Traceback (most recent call last): File "/home/siamak/workspace/test/com/tower/test/ocr2.py", line 1, in from PIL import _imaging as core ImportError: /home/siamak/.local/lib/python2.7/site-packages/PIL/_imaging.so: undefined symbol: PyUnicodeUCS4_AsLatin1String – Siamak Heshmati Feb 17 '16 at 23:23
  • @SiamakHeshmati Are you using Python on Windows? If so, this might help: http://stackoverflow.com/questions/26965487/undefined-symbol-pyunicodeucs4-aslatin1string-when-installing-pillow-for-local. Also, if you're using Python 2.6, you'll need to upgrade to 2.7. –  Feb 17 '16 at 23:29
  • I am using Python 2.7 on Ubuntu (Linux) – Siamak Heshmati Feb 17 '16 at 23:32
  • @SiamakHeshmati What error do you get when you use the exact code from your question, but replace `import Image` with `from PIL import Image`? –  Feb 17 '16 at 23:33
  • 1
    I did and : Traceback (most recent call last): File "/home/siamak/workspace/test/com/tower/test/ocr2.py", line 1, in from PIL import Image File "/home/siamak/.local/lib/python2.7/site-packages/PIL/Image.py", line 66, in from PIL import _imaging as core ImportError: /home/siamak/.local/lib/python2.7/site-packages/PIL/_imaging.so: undefined symbol: PyUnicodeUCS4_AsLatin1String – Siamak Heshmati Feb 17 '16 at 23:50
0

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

0

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.

Community
  • 1
  • 1
Jer K
  • 885
  • 8
  • 11