Reputation: 331
I get the error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-0f6709e38f49> in <module>()
----> 1 from PIL import Image
C:\Anaconda\lib\site-packages\PIL\Image.py in <module>()
61 from PIL import _imaging as core
62 if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
---> 63 raise ImportError("The _imaging extension was built for another "
64 " version of Pillow or PIL")
65
ImportError: The _imaging extension was built for another version of Pillow or PIL
Whenever I try to use the PIL library. I'm trying to load and work on a bunch of .gif's, and what I'm trying now, is the following:
from PIL import Image
Trying a different approach, through scipy with:
import scipy.ndimage as spnd
os.chdir('C:\\WeatherSink\\data\\')
spnd.imread('2014-11-03-0645.gif')
Fails with:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-23c383b79646> in <module>()
1 os.chdir('C:\\WeatherSink\\data\\')
----> 2 spnd.imread('2014-11-03-0645.gif')
C:\Anaconda\lib\site-packages\scipy\ndimage\io.pyc in imread(fname, flatten, mode)
36 from PIL import Image
37 except ImportError:
---> 38 raise ImportError("Could not import the Python Imaging Library (PIL)"
39 " required to load image files. Please refer to"
40 " http://pypi.python.org/pypi/PIL/ for installation"
ImportError: Could not import the Python Imaging Library (PIL) required to load image files. Please refer to http://pypi.python.org/pypi/PIL/ for installation instructions.
The first approach guides me towards the versions of PIL installed. I try emulating the getattr(...), and that returns None. So I'm not surprised that it's less than functioning. But does anyone know how to 'fix' the errors?
I'm running on win7, managing python2.7 through conda. I've tried to remove and re-install the packages as well, without any change in the output.
Help is much appreciated.
Upvotes: 23
Views: 36607
Reputation: 11
Reinstall the package which the error mentioned maybe also can help you. It works on my computer when pip install -U
don't work.
Upvotes: 0
Reputation: 1
i think acttually is the Virtual Environments you use when you run your code. many times computer will run Anaconda path instead of Python3. So you can try python or python 3 in command prompt before call your code. Example: python3 image.py. Or you can delete anaconda :D.
Upvotes: 0
Reputation: 99
This is a problem in python 3.6
Edit file: C:\Anaconda\lib\site-packages\PIL\Image.py
and change code:
if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
raise ImportError("The _imaging extension was built for another "
" version of Pillow or PIL")
change that to:
if core.PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
raise ImportError("The _imaging extension was built for another "
" version of Pillow or PIL")
This will solve the problem. Regards
Upvotes: 9
Reputation: 1326
This is only an installation issue.
First install pip on your system if it is not installed. It is available for Windows also.
Upgrade your numpy, pip/pillow, scipy:
pip install -U numpy
pip install -U pil/pillow
pip install -U scipy
The best option for Windows is to use anaconda.
I think pip is already installed in conda. This will resolve your system version issue.
In [1]: from PIL import Image
In [2]: import scipy.ndimage as spnd
In [3]: x = spnd.imread('ppuf100X91.gif')
In [4]: print x
[[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
...,
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]]
Upvotes: 22
Reputation: 31
This problem is because of Python package of PIL/pillow is Up or Down version of your system and due to this question is generate in your system.
Try to check this command:
sudo apt-get install python-PIL
Check this package is install or not. If it is installed than try to remove with the command:
sudo apt-get remove python-PIL
Check this will work to remove the PIL/pillow package is removed from your system.
And finally this command will help you to solve this package problem:
sudo apt-get autoremove python-PIL
Then reinstall PIL/Pillow package:
sudo apt-get install python-pil
This should help you solve the problem.
Upvotes: 3
Reputation: 4129
Maybe one of your dependencies requires PIL and PIL ends up being installed after Pillow, causing conflicts in your site packages dir. I'm assuming you're seeing that error because the import statement is importing _imaging
from a legitimate PIL installation and not a Pillow installation.
I've had trouble in the past with conflicting packages that require either PIL or Pillow. Pillow is, of course, the preferred package. I would take a look at the dependencies of your packages. If you can find one that depends on PIL, I would submit a pull request which changes the dependency to Pillow or maybe even create your own fork with that change. For my situation, forking was the option that I settled on since the project seemed to have had no activity on it for a long time.
Ultimately, you want to eliminate any dependencies on the PIL package (since it's no longer active) in favor of Pillow.
Upvotes: 3