Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name '_imaging' #3088

Closed
mrshwah opened this issue Apr 10, 2018 · 27 comments
Closed

ImportError: cannot import name '_imaging' #3088

mrshwah opened this issue Apr 10, 2018 · 27 comments

Comments

@mrshwah
Copy link

mrshwah commented Apr 10, 2018

What did you do?

Importing Pillow as a part of a flask project.

What did you expect to happen?

Pillow to be imported properly.

What actually happened?

File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 60, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging'

What versions of Pillow and Python are you using?

I'm using Python 3.5 and Pillow 5.1.0 on Ubuntu 16.

@mrshwah
Copy link
Author

mrshwah commented Apr 10, 2018

By the way, I have already tried to remove both PIL and pillow and then reinstalling them.

@aclark4life
Copy link
Member

>>> from PIL import _imaging
>>> 

@mrshwah
Copy link
Author

mrshwah commented Apr 10, 2018

Still getting the same error. This is in the PIL package that was pip installed along with Pillow, by the way. More context of the Image.py file:

try:
    # If the _imaging C module is not present, Pillow will not load.
    # Note that other modules should not refer to _imaging directly;
    # import Image and use the Image.core variable instead.
    # Also note that Image.core is not a publicly documented interface,
    # and should be considered private and subject to change.
    from PIL import _imaging
    if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
        raise ImportError("The _imaging extension was built for another "
                          "version of Pillow or PIL:\n"
                          "Core version: %s\n"
                          "Pillow version: %s" %
                          (getattr(core, 'PILLOW_VERSION', None),
                           PILLOW_VERSION))

@hugovk
Copy link
Member

hugovk commented Apr 10, 2018

Please can you paste the full traceback?

How did you install?

You don't want to install PIL separately, only pip install pillow.

@aclark4life
Copy link
Member

@nchouard You should pip install Pillow (or apt-get install python-pillow) then run Python then >>> from PIL import Image (or _imaging) using the same Python installation (i.e. make sure you don't have multiple versions of Python installed). You don't need to be doing anything "in the PIL package that was pip installed along with Pillow"… that's not relevant here.

@mrshwah
Copy link
Author

mrshwah commented Apr 10, 2018

Traceback (most recent call last):
[Tue Apr 10 15:00:53.665168 2018] [wsgi:error] [
  File "/var/www/parleyback/parleyback.wsgi", line 6, in <module>
[Tue Apr 10 15:00
    from app import create_app
[Tue Apr 10 15:00:53.665179 2018] [wsgi:error] [pid 
  File "/var/www/parleyback/app/__init__.py", line 4, in <module>
[Tue Apr 10 15:00
    from . import extensions, config, user, auth, voice, audio, site, call, payment
  File "/var/www/parleyback/app/user/__init__.py", line 2, in <module>
[Tue Apr 10 1
    from app import api
[Tue Apr 10 15:00:53.665196 2018] [wsgi:error] [pid 30736] 
  File "/var/www/parleyback/app/api.py", line 3, in <module>
[Tue Apr 10 15:00:53.6
    from app import utils
[Tue Apr 10 15:00:53.665205 2018] [wsgi:error] [pid 30736
  File "/var/www/parleyback/app/utils/__init__.py", line 6, in <module>
[Tue Apr 10
    from PIL import Image
[Tue Apr 10 15:00:53.665213 2018] [wsgi:error] [pid 30736
  File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 60, in <module>

    from . import _imaging as core
[Tue Apr 10 15:00:53.665231 2018] [wsgi:error] [
ImportError: cannot import name '_imaging'

Pillow was installed using pip. When I install pillow, however, it installs PIL as well. Is this an issue?

@mrshwah
Copy link
Author

mrshwah commented Apr 10, 2018

@aclark4life Ok, thanks. That is exactly what I do. The issue seems to be stemming from the error in the PIL/Image.py file though...

@aclark4life
Copy link
Member

@nchouard If you look at the source code right above line 60 you'll see this::

try:
    # If the _imaging C module is not present, Pillow will not load.
    # Note that other modules should not refer to _imaging directly;
    # import Image and use the Image.core variable instead.
    # Also note that Image.core is not a publicly documented interface,
    # and should be considered private and subject to change.

I think next you should paste the output of pip install Pillow as @hugovk suggested (although the wsgi:error is interesting … is this mod_wsgi by any chance?)

@mrshwah
Copy link
Author

mrshwah commented Apr 10, 2018

Yes, this is mod_wsgi.

Collecting Pillow
  Downloading Pillow-5.1.0-cp36-cp36m-manylinux1_x86_64.whl (2.0MB)
    100% |████████████████████████████████| 2.0MB 753kB/s
Installing collected packages: Pillow
Successfully installed Pillow-5.1.0

@mrshwah
Copy link
Author

mrshwah commented Apr 10, 2018

The _imaging file is present under the name: _imaging.cpython-36m-x86_64-linux-gnu.so

@aclark4life
Copy link
Member

@nchouard If you can from PIL import Image in Python then this is likely a mod_wsgi issue e.g. https://stackoverflow.com/a/43671174/185820

@mrshwah
Copy link
Author

mrshwah commented Apr 10, 2018

It looks like you're right, it's an issue with mod_wsgi and what it was compiled against. Thanks a lot for your help!

@mrshwah mrshwah closed this as completed Apr 10, 2018
@nise
Copy link

nise commented Mar 22, 2019

I though this is about an imaging library. Why do I need an Apache module?

The mod_wsgi package provides an Apache module that implements a WSGI compliant interface for hosting Python based web applications on top of the Apache web server.

@radarhere
Copy link
Member

@nise you don't, this is just a discussion about the problem that @nchouard was having when running Pillow in a Python hosted web application

@pedrodparkes
Copy link

get the same error running Pillow on AWS Lambda.
Is it possible to have Pillow on such kind of runtima?

@gweiying
Copy link

I had the same error as pedrodparkes on running pillow with Lambda, any fixes?

@aclark4life
Copy link
Member

@gweiying None that I know of, unless you, or someone reading this, are providing one in a pull request. Also, this ticket is closed? So presumably already fixed in latest Pillow, or being addressed in another issue somewhere.

@hugovk
Copy link
Member

hugovk commented Feb 13, 2020

The original issue was solved, please open a new issue with details, or you may get a quicker answer on Stack Overflow:

@patricio-ezequiel-hondagneu-roig

I ran into this problem using Pillow with Serverless + AWS Lambda too

@Moriuks
Copy link

Moriuks commented May 20, 2020

@patricio-ezequiel-hondagneu-roig did you find a solution?

@pedrodparkes
Copy link

I fixed an issue by preparing Lambda archive on Linux. It fails on Mac in the way described above.

@shesh909
Copy link

i tried pip uninstall pillow multiple times, and then did pip install pillow.
It worked!

@yagobatista
Copy link

I had the same problem with aws lambda when i update to python3.8, in my case a deployed using zappa==0.51.0 and Pillow==7.2.0, it turn out a forgot to change my runtime to "runtime": "python3.8" on the zappa_settings.json. I hope it helps someone else

@Tsingis
Copy link

Tsingis commented Feb 4, 2021

I'm having the this issue when using actions to build and deploy AWS Lambda with serverless. Anyone got a clue what should I do?

@jlavnv
Copy link

jlavnv commented Jan 8, 2022

There are no solution for AWS Lambda with serverless?

@aryan1107
Copy link

same issue in lambda no clue

@hugovk
Copy link
Member

hugovk commented Jan 23, 2022

The original issue was solved, please open a new issue with details, or you may get a quicker answer on Stack Overflow:

@python-pillow python-pillow locked as resolved and limited conversation to collaborators Jan 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests