Why can't Python import Image from PIL?

后端 未结 17 1812
执念已碎
执念已碎 2020-12-03 06:49

The single line that I am trying to run is the following:

from PIL import Image

However simple this may seem, it gives an error:

         


        
相关标签:
17条回答
  • 2020-12-03 07:03

    Any library/package you import must have its dependencies and subordinate parts in the same python directory. in linux if you

    Python3.x -m pip install <your_library_name_without_braces>

    what happens is, it installs on the default python. so first make sure that only 1 python 2.x and 1 python 3.x versions are on your pc.

    If you want to successfully install matplotlib you need these lines,

    python -m pip install matplotlib pillow numpy pandas
    

    the last 2 were auxiliary libs, and must have.

    0 讨论(0)
  • 2020-12-03 07:05

    For me, I had typed image with a lower case "i" instead of Image. So I did:

    from PIL import Image NOT from PIL import image

    0 讨论(0)
  • 2020-12-03 07:06

    Install Pillow from Command Line:

    python -m pip install pillow
    
    0 讨论(0)
  • 2020-12-03 07:07

    If you did all and it didn't work again like mien, do this copy Image.py and ImageTk.py from /usr/lib/python3/dist-packages/PIL on ubuntu and C:/Users/yourComputerName/AppData/Local/Programs/Python/Python36/Lib/PIL on windows to your projects directory and just import them!

    0 讨论(0)
  • 2020-12-03 07:13

    If you use Anaconda, you may try:

    conda install Pillow
    

    Example

    0 讨论(0)
  • 2020-12-03 07:14

    what that worked for me:

    go to the fodler

    C:\Users\{YOUR PC USER NAME}\AppData\Local\Programs\Python\Python37-32\Lib\site-packages 
    

    and either delete or change the name of the PIL folder and DONE.

    had to do it after running

    pip uninstall PIL
    

    as other suggested yielded for me

    WARNING: Skipping PIL as it is not installed.
    

    But I am not sure about the consequences of removing that library so I will edit this post if I ever get into a problem because of that.

    0 讨论(0)
提交回复
热议问题