未安装_imaging C模块(在Windows上)

abo*_*nov 6 python pdf django python-imaging-library

我正在尝试使用django/PIL/Imaging生成一些pdf,一切都很好,直到我尝试将一些图像放入pdf:

Exception Type: ImportError
Exception Value:    
The _imaging C module is not installed
Exception Location: D:\install\python27\lib\site-packages\PIL\Image.py in __getattr__, line 37
Python Executable:  D:\install\python27\python.exe
Python Version: 2.7.1
Python Path:    
['D:\\~Sasha\\Portman',
 'D:\\install\\python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg',
 'D:\\install\\python27\\lib\\site-packages\\pisa-3.0.33-py2.7.egg',
 'D:\\install\\python27\\lib\\site-packages\\html5lib-0.95-py2.7.egg',
 'D:\\install\\python27\\lib\\site-packages\\pypdf-1.13-py2.7.egg',
 'D:\\install\\PyCharm 2.0.2\\helpers',
 'D:\\~Sasha\\Portman',
 'D:\\~Sasha',
 'C:\\Windows\\system32\\python27.zip',
 'D:\\install\\python27\\DLLs',
 'D:\\install\\python27\\lib',
 'D:\\install\\python27\\lib\\plat-win',
 'D:\\install\\python27\\lib\\lib-tk',
 'D:\\install\\python27',
 'D:\\install\\python27\\lib\\site-packages',
 'D:\\install\\python27\\lib\\site-packages\\PIL']
Run Code Online (Sandbox Code Playgroud)

PIL是通过PIL网站的预编译捆绑安装的,导入_imaging正在提供此输出:

Python 2.7.1 (r271:86832, Feb  7 2011, 11:33:02) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: %1 is not a valid Win32 application.
Run Code Online (Sandbox Code Playgroud)

python x64会导致这个问题吗?

Python 2.7.1 (r271:86832, Feb  7 2011, 11:33:02) [MSC v.1500 64 bit (AMD64)] on win32
Run Code Online (Sandbox Code Playgroud)

我有一个预先构建的P64 x64包,并将其安装在现有的bundle之上,现在通过console导入确实有效:

>>> import _imaging
import _imaging # dynamically loaded from D:\install\python27\lib\site-packages\PIL\_imaging.pyd
Run Code Online (Sandbox Code Playgroud)

但在尝试生成pdf文件时,我一直收到同样的错误.

Joa*_*son 13

是的,这肯定是(并且很可能是)由x64问题引起的.如果您正在运行Python x64,则任何包含本机DLL的模块都需要安装在为x64编译的版本中.

编辑:我在PIL站点找不到x64的实际预编译版本,但如果您有兴趣自己编译,这里有一个起点.

  • @abolotnov刚刚测试过,来自http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil的PIL库的python x64适用于我.请务必先卸载旧的. (4认同)

Ahm*_*mad 7

我有同样的问题。我只是简单地卸载了

PIL

并安装了Pillow它的替代品PIL

pip install pillow

这对我有用。