python/django - “Cannot use ImageField because Pillow is not installed”

后端 未结 11 1166
一向
一向 2021-01-17 11:38

I\'m joining a project, so I want to set up the environnment, so what I did is :

pip install -r requirements.txt

This fully installed all r

相关标签:
11条回答
  • 2021-01-17 11:54

    I had the same problem in my virtual environment, even though Pillow was installed. Also installing a lower version didn't help. As soon I left my virtual environment it worked. Maybe this is helping someone.

    There is the command:

        (wb_env) C:\Users\Taranis\Dropbox\08_Coding\Python 
        Coding\Programme\Projekt_Webblog\tim_webblog>python manage.py makemigrations app_webblog
    

    The error:

        SystemCheckError: System check identified some issues:
    
        ERRORS:
        app_webblog.BlogEntry.entry_img: (fields.E210) Cannot use ImageField because 
        Pillow is not installed.
        HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "pip install 
        Pillow".
    
    0 讨论(0)
  • 2021-01-17 11:57

    I tried :

    • Reinstall globaly PIL by compiling "Imaging-1.1.7" using some instructions here, but didn't work
    • Reinstall Pillow and it's dependency globally using that link, but didn't work
    • Reinstall GCC4.2 using this link, but it didn't work

    I finally figured out I was in the case described in the wonderfull answer to this post. In other words, I am running a mac whose CPU is capable of 64bit but whose kernel firmware is set to 32bit. Which is a problem as the project I'm working on was built for 64bit.

    As explained in that post, when you install python3 using an installer (DMG) it will sniff if the kernel is set to 32 bit and install 32bit version of python 3 accordingly. But if you just download the tarball source from python's website and install it with :

    cd Python-3.4.1
    ./configure
    make
    sudo make install
    

    Then the 64bit version of python3 should be installed. Which you can verify by doing :

    file /usr/local/bin/python3
    /usr/local/bin/python3: Mach-O 64-bit executable x86_64
    

    That done, all problems are gone with PIL/Pillow in the virtualenv using this 64bit version of python3. Even the pip downgrade became unnecessary.

    0 讨论(0)
  • 2021-01-17 11:57

    I had this error using PyCharm's debugger. I had to go to Settings->'Project Interpreter' highlight 'Pillow' and hit the little up arrow on the right to upgrade it. Then the error disappeared.

    0 讨论(0)
  • 2021-01-17 11:58

    Had a similar problem, and my solution was much simpler:

    Apparently packages PIL and Pillow can't coexist. If you want to use Pillow you first have to uninstall PIL and then install Pillow.

    If you are on Mac, you have to install a few libraries as well using brew. Mentioned below is the sequence of steps:

    $pip uninstall PIL
    $brew install libtiff libjpeg webp little-cms2
    $pip install Pillow
    

    To test if pillow is installed and ready to use, open python interpreter and try to import the following:

    >>> from PIL import Image
    

    *note that the library still says PIL but now it is importing from Pillow instead of PIL.

    If you are able to successfully import then you are good to go (in all probability you won't have to worry about setting PYTHONPATH or 32/64-bit installations)

    Source: https://pillow.readthedocs.io/en/latest/installation.html

    0 讨论(0)
  • 2021-01-17 12:00

    For python3 make sure your $PYTHONPATH has the virtualenv path and Instead of running the command

    python manage.py migrate
    

    Run:

    python3 manage.py migrate
    
    0 讨论(0)
  • 2021-01-17 12:06

    What worked for me was to uninstall Pillow from user folder and install it with sudo.

    Initial install was:

    $ pip3 install Pillow --user
    

    installed to: ~/.local/lib/python3.7/site-packages/Pillow-7.0.0.dist-info

    So first uninstalled it and then installed with sudo:

    $ pip3 uninstall Pillow
    $ sudo pip3 install Pillow
    

    new location: /usr/local/lib64/python3.7/site-packages/Pillow-7.0.0.dist-info and problem was fixed.

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