Why can't Python import Image from PIL?

后端 未结 17 1810
执念已碎
执念已碎 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 06:58

    All the answers were great however what did it for me was a combination of uninstalling Pillow

    pip uninstall Pillow
    

    Then installing whatever packages you need e.g.

    sudo apt-get -y install python-imaging
    sudo apt-get -y install zlib1g-dev
    sudo apt-get -y install libjpeg-dev
    

    And then using easy_install to reinstall Pillow

    easy_install Pillow
    

    Hope this helps others

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

    I had the same issue, and did this to fix it:

    1. In command prompt

      pip install Pillow ##
      
    2. Ensure that you use

      from PIL import Image
      

    I in Image has to be capital. That was the issue in my case.

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

    had the same error while using pytorch code which had deprecated pillow code. since PILLOW_VERSION was deprecated, i worked around it by:

    Simply duplicating the _version file and renaming it as PILLOW_VERSION.py in the same folder.

    worked for me

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

    I had the same error. Here was my workflow. I first installed PIL (not Pillow) using

    pip install --no-index -f https://dist.plone.org/thirdparty/ -U PIL
    

    Then I found Pillow and installed it using

    pip install Pillow
    

    What fixed my issues was uninstalling both and reinstalling Pillow

    pip uninstall PIL
    pip uninstall Pillow
    pip install Pillow
    
    0 讨论(0)
  • 2020-12-03 07:00

    Now, I actually did some debugging with my brother and found that Pillow (PIL) needed to be initialized. I don't know how to initialize it, so you could probably stick with reinstalling Pillow.

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

    FWIW, the following worked for me when I had this same error:

    pip install --upgrade --force-reinstall pillow
    
    0 讨论(0)
提交回复
热议问题