2012-01-28 112 views
2

嗨我想要使用PIL能夠通過管理界面上傳圖片到我的django網站。麻煩PIL python

繼承人的測試我安裝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文件,但它仍然無法正常工作。試圖運行sudo python setup.py build我收到以下錯誤,當Upload a valid image. The file you uploaded was either not an image or a corrupted image.

另外:

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 

好像東西是錯誤的指針,我得到這個錯誤嗎?

+1

你安裝使用'pip' /'easy_install'或您的操作系統軟件包管理器? – 0xc0de 2012-01-28 06:36:07

+0

我下載了tar文件,並嘗試使用setup.py安裝 – locoboy 2012-01-28 19:23:54

回答

6

你必須在Mac安裝支持JPEG,例如,如果您使用的是自制的只是:

brew install jpeg 

或Ubuntu的

sudo apt-get install libjpeg62-dev 

你可能需要安裝庫,以便鏈接當PIL編譯時,它會知道在哪裏尋找JPEG支持。這對其他不支持的庫也是一樣的。

還有另外一個枕頭選項命名,你可以在這裏看看:http://pypi.python.org/pypi/Pillow

它只是處理比PIL更容易一些事情。此外,請檢查this

+0

+1使用Pillow – 2012-01-28 15:25:39

+0

我使用brew安裝但仍無法正常工作。當我嘗試'python setup.py build'時,我也在 – locoboy 2012-01-28 19:25:25

+0

上面得到以下錯誤在BUILDME文件中,它表示使用「python setup.py build_ext -i」,這對我很有用。請讓我知道這是否適用於你 – Hassek 2012-01-29 07:14:31

-1

可能需要編輯源文件包中的setup.py文件,並在構建和安裝PIL之前向jpeg庫的安裝位置添加適當的路徑。 PIL源中提供的安裝說明可能會有所幫助。

+0

我在哪裏可以找到jpeg安裝的路徑? – locoboy 2012-01-28 23:18:14

+0

我不確定。可能位於'/ usr/local'或'/ usr/local/lib',或者您可以閱讀[本文](http://www.brantsteen.com/blog/python-27-libjpeg-pil-on-osx /) – machaku 2012-01-28 23:55:25

+0

是的,我試圖改變它,仍然得到相同的錯誤,雖然:( – locoboy 2012-01-29 01:48:48