PIL and pillow. ImportError: cannot import name '_imaging' - python

Running
from PIL import Image
import pytesseract as pt
text = pt.image_to_string(Image.open("text.png"))
gives me
Traceback (most recent call last):
File "C:\Users\Rasmus\workspace\PythonMTGO\src\OCR.py", line 1, in <module>
from PIL import Image
File "C:\Users\Rasmus\AppData\Local\Programs\Python\Python35\lib\site-packages\PIL\Image.py", line 66, in <module>
from PIL import _imaging as core
ImportError: cannot import name '_imaging'
I installed pillow from https://pypi.python.org/pypi/Pillow/3.0.0 for python 3.5
I read an answer that PIL and pillow can't work together? But if I install from above link with the windows msi installer it'll install PIL and pillow and put it into C:\Users\Rasmus\AppData\Local\Programs\Python\Python35\Lib\site-packages
I've spend an entire day getting 3 lines of code to work. Hope anyone know what may be wrong.

What is your version of pillow,
Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from
PIL.Image import core as _imaging” instead.
this is the official document
https://pillow.readthedocs.io/en/5.1.x/installation.html#warnings

Uninstall and install pillow
mostly this will solve this issue

Related

Python error in opening image with PIL Image.Open()

I am trying to do some studies and automation related to image metadata.
from PIL import Image
Image.open("/Users/carlo/Desktop/JPEG 2/DSC_0393.jpeg")
This is the error that I am receiving:
Traceback (most recent call last):
File "/Users/carlo/PythonProjects/ImageMetaData_00/main.py", line 1, in <module>
from PIL import Image
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/Image.py", line 114, in <module>
from . import _imaging as core
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/_imaging.cpython-310-darwin.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/_imaging.cpython-310-darwin.so: mach-o, but wrong architecture
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/_imaging.cpython-310-darwin.so: mach-o, but wrong architecture
I am using Python 3.10, not sure what I am missing. Thanks!
It’s telling you you’ve got a version of PIL downloaded/installed, but it’s not suitable for your computer architecture. You’re probably on an M1 Mac instead of an Intel one. To fix this try these:
pip3 install wheel
pip3 install --no-cache-dir pillow
If that doesn't work, you can try to switch to using python via Rosetta.
Go to the Application folder -> Right-click on Terminal App -> Get Info
Tick Open with Rosetta option.
Also try reinstalling it: pip3 install pillow.
If all else fails try downgrading python and see if anything clicks.

imread from scipy.misc does not work on pycharm. I can't seem to install PIL either

from scipy.misc import imread
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: cannot import name 'imread'
If I run the first on pycharm, I get the following message. I've came across that I need to install PIL or Pillow to work with imread. However, trying to install PIL on pycharm gives me this warning.
warning I get
+) interpreter that I'm running on pycharm is:
'/Users/jeongseohyeong/anaconda3/envs/DL/bin/python' (python 3.6)
I've also seen posts that are saying pip install pil works. However, it doesn't seem to work for me (or at least it works for my jupyter notebook which is built in '/Users/jeongseohyeong/anaconda3/bin/python'). Any help would be appreciated.
Imread has been depreciated. Either roll back to scipy 1.1 so you can use it or use another module.

How to import Image in Python3.5 under windows from PIL/Pillow

I want to write a little app to convert some images.
I think to have to use Image.open(), so I have to import the Image module. Right?
If so, here my problem. I have read other questions like this but any of them worked for me. I tried:
import Image => ImportError: cannot import name 'VERSION'
from PIL import Image => ImportError: cannot import name 'VERSION'
from Pillow import Image => ImportError: No module named 'Pillow'
In documentation I read:
Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.
Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead.
In my virtual enviroment I had PIL and Pillow directory but pip list gave only Pillow (3.1.0) so, even reading other answers, I try to uninstall PIL using pip but it can't find PIL, so I just delete the directory PIL and installed Pillow-PIL (now it appears on pip list and there's the directory Pillow_PIL on my venv\Lib\site-packages\) now:
import Image => ImportError: No module named 'PIL'
from PIL import Image => ImportError: No module named 'PIL'
from Pillow import Image => ImportError: No module named 'Pillow'
from Pillow-PIL import Image => SyntaxError: invalid syntax (on the minus sign)
from Pillow_PIL import Image => ImportError: No module named 'Pillow_PIL'
apt-get install python-imaging => "apt-get" command unknow (my free translation)
So, what now?
Edit: full error is
Traceback (most recent call last):
File "prova.py", line 1, in <module>
import Image
File "D:\Python\Envs\possedimenti\lib\site-packages\Image.py", line 1, in <mod
ule>
from PIL.Image import *
File "D:\Python\Envs\possedimenti\lib\site-packages\PIL\Image.py", line 29, in
<module>
from PIL import VERSION, PILLOW_VERSION, _plugins
ImportError: cannot import name 'VERSION'
When you install Pillow, it installs a module that you import as PIL. Pillow-PIL is apparantly a "Pillow wrapper for PIL compatibility".
It is generally not a good idea to delete files from site-packages, but to use a package installer like pip to do it.
To remedy this, I would suggest uninstalling Pillow-PIL, PIL (if you have it) and Pillow, and then reinstalling just Pillow.
pip3 uninstall Pillow-PIL ; pip3 uninstall PIL ; pip3 uninstall Pillow ; pip3 install Pillow

Have pillow installed and yet getting 'ImportError: No module named PIL'

Pillow was working fine for me and then I got this error :
File "/usr/local/lib/python2.7/site-packages/PIL/Image.py", line 2452, in open
% (filename if filename else fp))
IOError: cannot identify image file 'dataSet/.DS_Store'
From answers on SO I got that it is possible I have both PIL and pillow installed and so I uninstalled PIL and installed pillow using easy_install and ever since then I keep getting this error.
ImportError: No module named PIL
I tried everything.
pip install image
pip install pillow
pip upgrade pip
import PIL from Image
pip --version gives : pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)
pip freeze | grep Pillow gives : Pillow==4.1.0
The code I'm running is:
import os
import cv2
import numpy as np
from PIL import Image
And at line 4 I keep getting the error
Traceback (most recent call last):
File "finder.py", line 4, in <module>
from PIL import Image
ImportError: No module named PIL
What else can I do to fix the situation? Did I read all the posts related to this topic on SO? Pretty much. And there are MANY posts related to it as well,but please,help me.
It seems that You have Installed Pillow for python3.*
pip install pillow
Install the right version for python2.7
from here
https://pypi.python.org/pypi/Pillow/4.0.0
python2.7 version has cp27 in it's name, download the right wheel file based on your system architecture.
pip install some-package.whl
I hope it helps.
Regarding the first error, this is an expected error:
File "/usr/local/lib/python2.7/site-packages/PIL/Image.py", line 2452, in open
% (filename if filename else fp))
IOError: cannot identify image file 'dataSet/.DS_Store'
You're trying to open a non-image with Pillow, and it's responding by saying it cannot open it. This is correct behaviour.
I guess you're trying to open all the images in a directory, but it's failing on .DS_Store, which a a metadata file created by macOS when viewing the contents of the directory. This file won't have existed before you looked in the directory with Finder, hence the code worked. What you need to do is either ignore this file (as you would with Thumbs.db on Windows), be more careful with globbing (eg. make sure only .jpg or .png or such) or handle the IOError with a try:/except IOError: block.

error importing pptx library python

i want to import pptx but i'm using this
import sys
sys.path.insert(0,'D:/apera/python27/python-pptx-0.5.6')
import pptx
but somehow it shows error like this
Traceback (most recent call last):
File "D:/apera/Workspace/Python scripting test 6/ppt.py", line 5, in <module>
import pptx
File "D:/apera/python27/python-pptx-0.5.6\pptx\__init__.py", line 15, in <module>
from pptx.api import Presentation # noqa
File "D:/apera/python27/python-pptx-0.5.6\pptx\api.py", line 14, in <module>
from pptx.package import Package
File "D:/apera/python27/python-pptx-0.5.6\pptx\package.py", line 16, in <module>
from .parts.image import Image, ImagePart
File "D:/apera/python27/python-pptx-0.5.6\pptx\parts\image.py", line 13, in <module>
import Image as PIL_Image
ImportError: No module named Image
and when i want to install PIL it can't install for 64 bit. Is there a ppt library that don't need PIL?
remove the PIL package due to conflicts with Pillow and python-pptx
Delete the PIL directory located in C:\Users\user1\AppData\Local\Continuum\Anaconda\Lib\site-packages\ or wherever your library is
run pip install python-pptx to install Pillow
I had about the same issue. When I updated the pillow library (pretty easy to do with Anaconda which I use) the issue was gone.
Uninstall Pillow
Uninstall python-pptx
Install Pillow
Install python-pptx
Run above commands using "pip". This worked for me.
I had the same problem.
My system is Windows XP 32bit and the python version is 2.7.13.
I just degraded the version of pillow and python-pptx. It worked for me
pip install pillow==3.1.0
pip install python-pptx==0.5.5

Categories