我一直在努力解决这个错误两天,尝试了堆栈溢出的所有答案,但没有运气。我有一个使用Django图像字段的简单模型
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.EmailField()
url = models.URLField(blank=True, null=True)
short_bio = models.TextField(max_length=200, blank=True, null=True)
long_bio = models.TextField(max_length=5000, blank=True, null=True)
role = models.ManyToManyField(AuthorRole)
facebook_link = models.URLField(blank=True, null=True)
linkedin_link = models.URLField(blank=True, null=True)
twitter_link = models.URLField(blank=True, null=True)
gplus_link = models.URLField(blank=True, null=True)
thumbnail = models.ImageField(upload_to='images/', default='images/user_default.jpg')
在生产服务器中,当我从管理员访问模型并选择图像并尝试保存时,它会抛出以下错误。我多次安装和卸载枕头。尝试了不同版本的django和枕头。顺便说一下,它在当地环境中工作正常。
[:error] [pid 20256:tid 139822013380352] [remote 72.48.102.12:60881]
from PIL import Image
[:error] [pid 20256:tid 139822013380352] [remote 72.48.102.12:60881] File"/home/.virtualenvs/wcsenvpython3/lib/python3.4/sitepackages/PIL/Image.py", line 67, in <module>
[:error] [pid 20256:tid 139822013380352] [remote 72.48.102.12:60881]
from PIL import _imaging as core
[:error] [pid 20256:tid 139822013380352] [remote 72.48.102.12:60881] ImportError:cannot import name _imaging
我可以从manage.py shell执行from PIL import _imaging
。所以看起来pythonpath配置正确。
在我的virtualenv中,我可以看到_imaging.cpython-34m.so文件,但没有 _imaging.py文件。
我的服务器托管在linode中。这是Ubuntu 14.04。我正在使用Apache2。 Python 3.4.3。 Django 1.10枕头3.3.0。你的帮助非常明显。这个错误让我困扰了很久。
1:http://i.stack.imgur.com/nH8O3.jpg 2:http://i.stack.imgur.com/Vpdoe.jpg
答案 0 :(得分:1)
好吧,我终于得到了答案。它与枕头无关。我向公众提供了对“媒体”文件夹的写入权限,其中保存了图像并突然解决了问题。我不确定这是否是一个安全漏洞,但它解决了错误。
我是如何找到的:
我决定从PIL更改Image.py文件。
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 as core
if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
raise ImportError("The _imaging extension was built for another "
" version of Pillow or PIL")
except ImportError as v:
core = _imaging_not_installed()
# Explanations for ways that we know we might have an import error
if str(v).startswith("Module use of python"):
# The _imaging C module is present, but not compiled for
# the right version (windows only). Print a warning, if
# possible.
warnings.warn(
"The _imaging extension was built for another version "
"of Python.",
RuntimeWarning
)
elif str(v).startswith("The _imaging extension"):
warnings.warn(str(v), RuntimeWarning)
elif "Symbol not found: _PyUnicodeUCS2_" in str(v):
# should match _PyUnicodeUCS2_FromString and
# _PyUnicodeUCS2_AsLatin1String
warnings.warn(
"The _imaging extension was built for Python with UCS2 support; "
"recompile Pillow or build Python --without-wide-unicode. ",
RuntimeWarning
)
elif "Symbol not found: _PyUnicodeUCS4_" in str(v):
# should match _PyUnicodeUCS4_FromString and
# _PyUnicodeUCS4_AsLatin1String
warnings.warn(
"The _imaging extension was built for Python with UCS4 support; "
"recompile Pillow or build Python --with-wide-unicode. ",
RuntimeWarning
)
# Fail here anyway. Don't let people run with a mostly broken Pillow.
# see docs/porting.rst
raise
except块检查几个条件,最后一行再次引发导入错误。我评论了raise
,宾果游戏向我展示了许可错误。
我不知道为什么在地球上它显示导入错误,而问题是许可。我希望枕头的编写者能够查看此事并尝试生成相关的错误消息,而问题并非真正导入错误而是权限错误。