0

基于django1.9+python2.7的应用,在本地测试上传图片到七牛云存储没有问题,但是部署到sae后报出异常:

新浪sae下的异常信息:
ImportError at /admin/myblog/essay/add/
cannot import name _imagingRequest Method: POST 
Request URL: http://delve.applinzi.com/admin/myblog/essay/add/ 
Django Version: 1.9.1 
Exception Type: ImportError 
Exception Value: cannot import name _imaging 
Exception Location: /data1/www/htdocs/118/delve/1/delve/../delvevenv27/Lib/site-packages/PIL/Image.py in <module>, line 66 
Python Executable: /usr/bin/python 
Python Version: 2.7.9 
Python Path: ['/data1/www/htdocs/118/delve/1/delve/../delvevenv27/Lib/site-packages',
 '/data1/www/htdocs/118/delve/1',
 '/usr/local/sae/python/lib/python27.zip',
 '/usr/local/sae/python/lib/python2.7',
 '/usr/local/sae/python/lib/python2.7/plat-linux2',
 '/usr/local/sae/python/lib/python2.7/lib-tk',
 '/usr/local/sae/python/lib/python2.7/lib-old',
 '/usr/local/sae/python/lib/python2.7/lib-dynload',
 '/usr/local/sae/python/3rd/django-1.9.1',
 '/usr/local/sae/python/lib/python2.7/site-packages'] 
Server time: Mon, 18 Jan 2016 09:40:42 +0800 

我的模型代码是:

model.py
class Essay(models.Model):
    ...
     cover = models.ImageField(
        upload_to='upload/%Y/%m/%d/',
        verbose_name='文章封面',
        null=True,
        blank=True,
    )
    ...

七牛配置没有问题,因为本地测试可以通过

2016-01-18 提问
1 个回答
0

已采纳

应该是缺少PIL对应的c extension所依赖的库文件。
你可以到delvevenv27/Lib/site-packages/PIL/目录下:

  1. 查看_imaging.so是否存在

  2. 如果存在使用ldd查看_imaging.so的依赖是否存在
    这是我的机器上的依赖关系:

        >ldd _imaging.so
        
        linux-vdso.so.1 =>  (0x00007fff6f3ff000)
        libjpeg.so.62 => /usr/lib64/libjpeg.so.62 (0x00007f5c2964a000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f5c29434000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f5c29216000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f5c28e82000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003157200000)
    

如果不存在就需要安装对应的模块,重新安装PIL。

撰写答案

推广链接