PIL python的麻烦

时间:2012-01-28 04:45:55

标签: python django macos python-imaging-library

您好我正在尝试使用PIL通过管理界面将图像上传到我的django网站。

我在安装PIL后运行测试的结果:

cfarm:Imaging-1.1.7 christopherfarm$ python selftest.py 
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY 
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from /Library/Python/2.6/site-packages/PIL
--------------------------------------------------------------------
*** PIL CORE support not installed
*** TKINTER support not installed
*** JPEG support not installed
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not installed
*** LITTLECMS support not installed
--------------------------------------------------------------------
Running selftest:
*****************************************************************
Failure in example:
try:
 _info(Image.open(os.path.join(ROOT, "Images/lena.jpg")))
except IOError, v:
 print v
from line #24 of selftest.testimage
Expected: ('JPEG', 'RGB', (128, 128))
Got: decoder jpeg not available
1 items had failures:
   1 of  57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.

对于这个我来说,我有点新手,有没有办法让所有类型都得到支持?我还尝试上传.png文件但它仍然无法正常工作。我收到错误:Upload a valid image. The file you uploaded was either not an image or a corrupted image.

同样在尝试运行sudo python setup.py build时,我收到以下错误:

cfarm:Imaging-1.1.7 christopherfarm$ sudo python setup.py build
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imaging' extension
creating build/temp.macosx-10.6-universal-2.6
creating build/temp.macosx-10.6-universal-2.6/libImaging
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -DHAVE_LIBJPEG -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/opt/local/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _imaging.c -o build/temp.macosx-10.6-universal-2.6/_imaging.o
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
l_imaging.c:3281: fatal error: error writing to -: Broken pipe
compilation terminated.
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
^R
lipo: can't open input file: /var/tmp//ccuPSrVi.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1

似乎指针有问题?

3 个答案:

答案 0 :(得分:6)

如果您只使用自制程序,则必须安装对JPEG的支持,例如在Mac中:

brew install jpeg

或ubuntu

sudo apt-get install libjpeg62-dev

您可能需要链接已安装的库,因此当PIL编译时,它将知道在哪里查找JPEG支持。对于其他不受支持的库,这将是相同的。

还有另一个名为pillow的选项,您可以在这里查看:http://pypi.python.org/pypi/Pillow

它比PIL更容易处理一些事情。另请检查this

答案 1 :(得分:0)

如果brew对libjpeg不起作用,可以下载一个很好的libjpeg包。我在这里写到:

http://markliu.me/2011/aug/20/installing-libjpeg-and-pil-on-osx-snow-leopard-wit/

答案 2 :(得分:-1)

在构建和安装PIL之前,您可能需要编辑源包中的setup.py文件并添加适当的路径到jpeg库的安装位置。 PIL源中提供的安装说明可能会有所帮助。