Error using Pillow: ImportError: cannot import name _imaging - python

I've read the answers for similar questions but none of them seem to work for my situation.
When trying to use Pillow, I get this error:
>>> from PIL import Image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 63, in <module>
from PIL import _imaging as core
ImportError: cannot import name _imaging
In my /Library/Python/2.7/site-packages directory I have one PIL directory which contains the Image module and then I have PIllow-master directory which contains _imaging.c, so I don't understand why in Image.py line 63 says to import _imaging from PIL.
I've tried also to cut _imaging.c from Pillow-master and paste it in PIL but it doesn't work.
When trying to import Image, I'm into PIL.
If I try to import it while I'm into site-packages it doesn't work and says "no module named PIL".

Try to remove your PIL library and install new by:
pip install PIL --allow-external PIL --allow-unverified PIL

Related

Python loading wrong Pillow (PIL) package

I have strange issue while loading matplotlib package. Never observed that before. The package is trying to load PIL from the wrong place. If I try to load PIL from the command line, it also loaded from the wrong place.
Here is matplotlib traceback:
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/XXX/python_rep/miniconda3/envs/work/lib/python3.9/site-packages/matplotlib/__init__.py", line 113, in <module>
from . import _api, _version, cbook, _docstring, rcsetup
File "/home/XXX/python_rep/miniconda3/envs/work/lib/python3.9/site-packages/matplotlib/rcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "/home/XXX/python_rep/miniconda3/envs/work/lib/python3.9/site-packages/matplotlib/colors.py", line 51, in <module>
from PIL import Image
File "/homeappl/common-software/sw/python3.6/lib/python3.6/site-packages/PIL/Image.py", line 69, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/homeappl/common-software/sw/python3.6/lib/python3.6/site-packages/PIL/__init__.py)
Please note that I use my own conda environment with python 3.9
It is activated and contained Pillow version 9.0.0
Other packages are loaded from that instance, but bloody PIL tries to reach the common area.
/home/XXX/python_rep/miniconda3/envs/work/bin/python3.9 -m pip install pillow
Requirement already satisfied: pillow in /homeappl/common-software/sw/python3.6/lib/python3.6/site-packages (7.0.0)
I have no idea why it tries to load package from old place. But I do not have access to that - due to admin rights.
How to force machine not to use wrong package?

why can't I use pillow when I have pillow? [duplicate]

This question already has answers here:
Package (Python PIL/Pillow) installed but I can't import it
(3 answers)
Closed last year.
E:\python>pyota.py
Traceback (most recent call last):
File "E:\python\pyota.py", line 6, in <module>
import PILLOW
ModuleNotFoundError: No module named 'PILLOW'
E:\python>pip install pillow
Requirement already satisfied: pillow in c:\users\admin\appdata\local\programs\python\python310\lib\site-packages (9.0.0)
Even if I used 'pillow' it didn't work:
Traceback (most recent call last):
File "E:\python\pyota.py", line 6, in <module>
import pillow
ModuleNotFoundError: No module named 'pillow'
The download module is called "pillow", but the import is PIL (Python Imaging Library). Pillow was forked from PIL as a clone, and was improved so much that it has replaced it.
from PIL import Image
or
import PIL

ImportError: No module named PIL, even though module seems to be installed

When trying to import the PIL module, which I previously pip-installed, I get the following error:
Traceback (most recent call last):
File "/Users/user1/Desktop/script.py", line 94, in <module>
from PIL import Image, ImageDraw, ImageFont
ImportError: No module named PIL
My script is run in /usr/local/bin/python3 the modules are saved at /usr/local/bin/pip3. When typing pip3 list in the terminal, "Pillow" also seems to exist.
Is there a way to fix the error? What could have caused it ?
relevant part of code:
# -*- coding: utf-8 -*-
# !/usr/local/bin/python3
import os
from PIL import Image, ImageDraw, ImageFont

Cannot import imaging from PIL

Traceback (most recent call last):
File "/home/raghav/Desktop/Everything/TinderAutomation-master/img_scrape.py", line 1, in <module>
from skimage.io import imread, imsave, imshow, show
File "/usr/local/lib/python3.7/dist-packages/skimage/io/__init__.py", line 7, in <module>
from .manage_plugins import *
File "/usr/local/lib/python3.7/dist-packages/skimage/io/manage_plugins.py", line 24, in <module>
from .collection import imread_collection_wrapper
File "/usr/local/lib/python3.7/dist-packages/skimage/io/collection.py", line 11, in <module>
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 60, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)
I've problem importing imaging modules like matplotlib and skimage.io. I'm fairly new to python. Can anyone help me with this problem?
Try this: I first installed PIL (not Pillow) using
pip3 install --no-index -f https://dist.plone.org/thirdparty/ -U PIL
Then I found Pillow and installed it using
pip3 install Pillow
What fixed my issues was uninstalling both and reinstalling Pillow
pip3 uninstall PIL
pip3 uninstall Pillow
pip3 install Pillow

Error importing Images from PIL: The _imaging extension was built for another version of Pillow or PIL

I want to work with images in python, but I get an error when I try to use PIL. I want to import images from PIL with the following command:
from PIL import Image
But I get the following error:
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
from PIL import Image
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\Image.py", line 56, in <module>
from . import _imaging as core
ImportError: DLL load failed: A megadott eljárás nem található.
(The last sentence translates to 'The specified procedure could not be found')
I followed the instructions under this question and uninstalled Pillow 4.1.0 and reinstalled Pillow 4.0.0. It didn't solve my problem, but now I get a different error message:
Warning (from warnings module):
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\Image.py", line 74
# Explanations for ways that we know we might have an import error
RuntimeWarning: The _imaging extension was built for another version of Pillow or PIL
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
from PIL import Image
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\Image.py", line 58, in <module>
raise ImportError("The _imaging extension was built for another "
ImportError: The _imaging extension was built for another version of Pillow or PIL
Following the instructions on another question I uninstalled PIL (but failed because it wasn't installed in the first place), then uninstalled pillow, and then reinstalled pillow (the newest version), but I still get the second error message.
I am using windows 8.1 and python 3.6.0. Does anybody know how to solve this problem?

Categories