Django错误:由于未安装Pillow,因此无法使用ImageField [英] Django Error: Cannot use ImageField because Pillow is not installed

查看:611
本文介绍了Django错误:由于未安装Pillow,因此无法使用ImageField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习如何使用Django开发Web服务.在学习有关Udemy的在线课程时,我在models.py中使用ImageField遇到了问题.我的问题是,当我执行runserver命令时,尽管我非常确定已安装库Pillow,但Django显示以下错误.

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.

在models.py中,我有以下代码:

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


运行服务器时,出现以下错误: python manage.py运行服务器 正在执行系统检查...


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']

['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']

如何解决此问题?或者,是否可以在没有Pillow的情况下在Django中使用图像?

How can I fix this problem? Or, is there any alternative to use images in Django without Pillow?

推荐答案

为了在pycharm中为您的项目定义virtualenv,请首先转到以下路径:

In order to define a virtualenv for your project in pycharm, first go to this path :

文件->设置->项目->项目解释器

file -> settings -> Project -> Project Interpreter

现在您可以看到在pycharm中打开的所有项目.选择所需的项目,然后点击项目解释器配置按钮,然后选择添加本地python解释器.在这种形式下,选择现有环境.现在在解释器中的按钮中,您可以选择所需的virtualenv(myvirtualenv-> bin-> python3.x)

now you can see all project that are opened in pycharm. select your desired project, and click Project Interpreter config button, then select Add local python interpreter. in this form, select Existing environment. now in button inside Interpreter you can select your desired virtualenv (myvirtualenv -> bin -> python3.x)

这篇关于Django错误:由于未安装Pillow,因此无法使用ImageField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆