I'm currently learning how to use Django to develop a web service. As I go through an online course on Udemy, I ran into a problem using ImageField in models.py. My problem is that, when I excute the runserver command, Django shows the following error although I am pretty sure the library Pillow is installed.
In models.py, I have the following code:
from django.db import models
from django.contrib.auth.models import User
class UserProfileInfo(models.Model):
user = models.OneToOneField(User, on_delete=models.PROTECT)
portfolio = models.URLField(blank=True)
picture = models.ImageField(upload_to="profile_pics")
def __str__(self):
return user.self.username
When I runserver, I get the following error: python manage.py runserver Performing system checks...
Unhandled exception in thread started by <function check_errors<locals>.wrapper at 0x10407b6a8>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/django/core/management/base.py", line 410, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check
identified some issues:
ERRORS:
first_app.UserProfileInfo.picture: (fields.E210) Cannot use ImageField because
Pillow is not installed.
HINT: Get Pillow at https://pypi.python.org/pypi/Pillow or run command "pip
install Pillow".
System check identified 1 issue (0 silenced).
So, by following the message I checked the installed modules by using the method introduced here: How can I get a list of locally installed Python modules?. The following code is run in a file in the same directory as manage.py. I'm using Pycharm to use a virtual environment, so I am assuming I'm using the same environment as the Django project uses when I run server.
As the result of the method above, I could see Pillow is installed, like this:
['argon2==0.1.10', 'bcrypt==3.1.4', 'cffi==1.11.5', 'django==2.0.5', 'faker==0.8.15', 'olefile==0.45.1', 'pillow==5.0.0', 'pip==9.0.1', 'pycparser==2.18', 'python-dateutil==2.7.3', 'pytz==2018.4', 'setuptools==28.8.0', 'six==1.11.0', 'text-unidecode==1.2']
How can I fix this problem? Or, is there any alternative to use images in Django without Pillow?