-1

I am having problems with the module PIL/Pillow. I installed it with pip install pillow and everything worked fine. But when I start a program that needs this module, it recognizes it, but shows the following error message: ImportError: cannot import name '_imaging' from 'PIL' (see picture).

from PIL import Image

[Click to see the Pic with the Error]

See also these pictures:

Script-Code

Image.py

It seems that many have this problem, but I have not found a solution to my problem anywhere. Neither in the forum nor in Google. How do I fix this?

Python version: 3.8.2

Pillow version: 8.1.0

PyBeginner
  • 15
  • 5
  • 1
    It does not look like `PIL` is installed correctly — none of its script should have `desktop` as part of their path (as appears to be the case in the screenshot). To see if it is installed type `pip list` at the command prompt and see if there's a `Pillow` and version number in the list it displays. – martineau Jan 05 '21 at 12:39
  • https://stackoverflow.com/search?q=%5Bpython-imaging-library%5D+ImportError%3A+cannot+import+name+%27_imaging%27+from+%27PIL%27 – phd Jan 05 '21 at 12:52
  • I entered it and it shows me in the list only Pillow with version 8.1.0. The module PIL is not displayed at all. – PyBeginner Jan 05 '21 at 13:07

1 Answers1

0

This can happen because you have PIL and Pillow installed. Pillow is a fork of PIL and is the maintained library. It is recommended not to use PIL because it has become outdated. Here are the steps to fix the problem:

pip uninstall PIL
pip uninstall pillow

then:

pip install pillow

If this doesn't solve the problem, go into your python site-packages or dist-packages and remove any files or folders related to PIL or pillow, then:

pip install pillow
DapperDuck
  • 2,728
  • 1
  • 9
  • 21
  • When I try to do "pip uninistall PIL" it tells me "WARNING: Skipping PIL as it is not installed". But when I do "pip uninstall pillow" it tells me: Found existing installation: Pillow 8.1.0 Uninstalling Pillow-8.1.0: Would remove: c:\users\300330\appdata\roaming\python\python38\site-packages\pil\* c:\users300330\appdata\roaming\python\python38\site-packages\pillow-8.1.0.dist-info\* Proceed (y/n)? When I type yes it deletes both PIL and Pillow for me, is this normal? ... – PyBeginner Jan 05 '21 at 13:12
  • Their installation might have been messed up because they share file names, but I'm not sure. Once you reinstall pillow does it work? – DapperDuck Jan 05 '21 at 13:15
  • The cmd shows me the following text: Defaulting to user installation because normal site-packages is not writeable Collecting pillow Using cached Pillow-8.1.0-cp38-cp38-win_amd64.whl (2.2 MB) Installing collected packages: pillow Successfully installed pillow-8.1.0 Seems to be installed correctly. Then I drag it into the folder where the .py file is located and start the script. It comes again the same error message...Idk why. I always copy both files into the folder, the PIL and the Pillow file, both. Do I only need one of the two? – PyBeginner Jan 05 '21 at 14:10
  • You don't need to drag the installation into the folder. Keep the file where it was when it was downloaded. – DapperDuck Jan 05 '21 at 14:11
  • If I don't copy this into the folder, and leave it in .../Roaming/Python38/site-packeages, the script doesn't recognize it and says no PIL module found – PyBeginner Jan 05 '21 at 14:14
  • In the command prompt, type python, then in the shell, type: `from PIL import Image` – DapperDuck Jan 05 '21 at 14:18
  • Then no error message comes, seems to work, but when I run it in a script program like PyCharm it shows me the error – PyBeginner Jan 05 '21 at 14:22
  • that's strange, could you please share your code? – DapperDuck Jan 05 '21 at 14:38
  • The code is just "from PIL import Image".When I enter that and click on "Run" the error below comes up without having specified another code, As seen on the picture, something seems to be wrong with the ___init___.py with the line: "from . import _imaging as core" in the pillow library – PyBeginner Jan 05 '21 at 15:09
  • It appears that image.py is in the desktop directory. Delete all past pillow files and then reinstall pillow using pip – DapperDuck Jan 05 '21 at 15:17
  • Should I then leave it in the folder where it was downloaded with pip? Do I then have to paste the .py file into the site-packages folder and start it so that it recognizes the module or how? – PyBeginner Jan 06 '21 at 12:24
  • You keep the pillow file in the site-packages folder, and you keep the file you're working on in any place you want. – DapperDuck Jan 06 '21 at 12:29
  • But keep it in a separate folder, not in program files or any restricted folder like that! – DapperDuck Jan 06 '21 at 12:30
  • That mean: if I install "pip install pillow" in the site packeges and leave it there and have my .py file on the desktop and work with it, it must still recognize the Pillow module in the site-packeges? – PyBeginner Jan 06 '21 at 12:39
  • Indeed, that should work – DapperDuck Jan 06 '21 at 12:40
  • If all else fails, you can go [here](https://pypi.org/project/Pillow/#files), and download the wheel file. Then there are tutorials how to download wheel files through pip. – DapperDuck Jan 06 '21 at 12:49
  • If I don't have the module in the same folder as the py file, it tells me no module found, even though it is a pip install in global. With the pip install + wheel file I also tried... without success – PyBeginner Jan 06 '21 at 17:57
  • hmm, I think there might have been an issue with your python installation and adding it to the PythonPath. I recommend uninstalling and reinstalling python. – DapperDuck Jan 06 '21 at 18:11
  • I have also tried, unfortunately without success... I tried it with PyCahrm, and installed Pillow over PyCahrm, and now when I work with PyCharm it works. The problem was probably the other script program... otherwise I can not explain it. Thanks anyway for the effort and the tips, I appreciate it very much! – PyBeginner Jan 08 '21 at 09:38
  • That's good to know! If you benefited from my answer please mark it as accepted for future reference. Thanks! – DapperDuck Jan 08 '21 at 12:05
  • How can I do this? Am new to the platform – PyBeginner Jan 08 '21 at 12:10
  • You press the grey checkmark on the left of my answer. It should turn green. Thanks! – DapperDuck Jan 08 '21 at 14:16