I looked at a lot of SO posts for this error and none of the answers address or resolve the error. Here is the pipfile:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
django = "*"
boto3 = "*"
psycopg2 = "*"
pillow = "*"
django-storages = "*"
django-crispy-forms = "*"
django-s3-storage = "*"
zappa-django-utils = "*"
psycopg2-binary = "==2.8.6"
django-environ = "*"
django-mptt = "*"
djangorestframework = "*"
mortgage = "*"
stripe = "*"
django-phonenumber-field = "*"
phonenumbers = "*"
django-mathfilters = "*"
image = "*"
[dev-packages]
mock = "*"
model-mommy = "*"
django-debug-toolbar = "*"
[requires]
python_version = "3.8"
As you can see, I have both the pillow and image packages installed. But, when I run py manage.py shell
, I get this error:
import PIL
ModuleNotFoundError: No module named 'PIL'
In my user_profile app
, I have the following:
import PIL
from PIL import Image
...
I tried uninstalling different PIL-related packages, I could run py manage.py shell
without running into the ModuleNotFoundError: No module named 'PIL'
. However, once deployed using AWS lambda
, I ran into another error:
[ERROR] ImportError: cannot import name '_imaging' from 'PIL' (/var/task/PIL/__init__.py)
...
File "/var/task/comments/models.py", line 5, in <module>
from user_profile.models import UserProfile
File "/var/task/user_profile/models.py", line 13, in <module>
from PIL import Image
File "/var/task/PIL/Image.py", line 114, in <module>
from . import _imaging as core
So, I went back and installed pillow (pipenv install pillow
) which shows up in my Pipfile as pillow = "*"
. Once again deployed using AWS Lambda, and once again the same error message as above (from . import _imaging as core
)