2013-07-30 38 views
9

對於那些誰需要知道,我是運行64位的Ubuntu 12.04,並試圖使用PIP安裝python3.2Ubuntu的Tkinter的安裝不包括PyImagingPhoto

對於項目運行問題劇本我正在寫我想在tkinter窗口中顯示圖像。要通過PIP和安裝的Tkinter的Python 3爲此,我裝枕頭,像這樣:

pip-3.2 install pillow #install stuff here 
sudo apt-get install python3-tk 

然後我試圖運行下面的腳本

import tkinter 
from PIL import Image, ImageTk 

root = tkinter.Tk() 
i = Image.open(<path_to_file>) 
p = ImaageTk.PhotoImage(i) 

還有更精彩的,但該塊拋出的錯誤。不管怎麼說,當我嘗試運行此我得到以下錯誤輸出

/usr/bin/python3.2 "/home/anish/PycharmProjects/Picture Renamer/default/Main.py" 
Traceback (most recent call last): 
    File "/usr/local/lib/python3.2/dist-packages/PIL/ImageTk.py", line 184, in paste 
    tk.call("PyImagingPhoto", self.__photo, block.id) 
_tkinter.TclError: invalid command name "PyImagingPhoto" 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/home/anish/PycharmProjects/Picture Renamer/default/Main.py", line 26, in <module> 
    n = Main("/home/anish/Desktop/Images/") 
    File "/home/anish/PycharmProjects/Picture Renamer/default/Main.py", line 11, in __init__ 
    self.PictureList = self.MakeImageList(self.dir) 
    File "/home/anish/PycharmProjects/Picture Renamer/default/Main.py", line 21, in MakeImageList 
    tkim = ImageTk.PhotoImage(temp_im) 
    File "/usr/local/lib/python3.2/dist-packages/PIL/ImageTk.py", line 123, in __init__ 
    self.paste(image) 
    File "/usr/local/lib/python3.2/dist-packages/PIL/ImageTk.py", line 188, in paste 
    from PIL import _imagingtk 
ImportError: cannot import name _imagingtk 

Process finished with exit code 1 

谷歌搜索再多給我一個解決方案爲主題我覺得就這通常說來重新安裝Tkinter的和/或枕頭。

這裏是我的/usr/lib/python3.2/tkinter/

['dialog.py', 'scrolledtext.py', 'simpledialog.py', 'tix.py', 'dnd.py', 'ttk.py', '__main__.py', '_fix.py', 'font.py', '__pycache__', 'messagebox.py', '__init__.py', 'commondialog.py', 'constants.py', 'colorchooser.py', 'filedialog.py'] 

的內容,這裏是我的/usr/local/lib/python3.2/dist中的[多]文件-Packages/PIL/

['OleFileIO.py', 'ImageFileIO.py', 'ImageCms.py', 'GimpGradientFile.py', 'PSDraw.py', 'ImageDraw2.py', 'GimpPaletteFile.py', 'TiffImagePlugin.py', 'ImageChops.py', 'ImageShow.py', 'ImageStat.py', 'FliImagePlugin.py', 'ImageColor.py', 'XpmImagePlugin.py', 'ImageOps.py', 'ExifTags.py', 'FpxImagePlugin.py', 'PngImagePlugin.py', 'ImageFile.py', 'WalImageFile.py', 'PixarImagePlugin.py', 'PsdImagePlugin.py', '_util.py', 'ImageDraw.py', 'GribStubImagePlugin.py', 'ContainerIO.py', 'CurImagePlugin.py', 'JpegPresets.py', '_imagingft.cpython-32mu.so', '_imagingmath.cpython-32mu.so', 'PpmImagePlugin.py', 'BmpImagePlugin.py', 'XbmImagePlugin.py', 'DcxImagePlugin.py', 'PaletteFile.py', 'SunImagePlugin.py', 'BufrStubImagePlugin.py', 'JpegImagePlugin.py', 'SpiderImagePlugin.py', 'ImageEnhance.py', 'TgaImagePlugin.py', 'IcnsImagePlugin.py', 'MspImagePlugin.py', 'ImageSequence.py', 'GifImagePlugin.py', 'ImageTransform.py', 'FontFile.py', 'GbrImagePlugin.py', 'EpsImagePlugin.py', 'XVThumbImagePlugin.py', 'BdfFontFile.py', 'PcdImagePlugin.py', 'TarIO.py', 'FitsStubImagePlugin.py', 'ImageMode.py', 'ArgImagePlugin.py', 'IcoImagePlugin.py', '_imaging.cpython-32mu.so', 'McIdasImagePlugin.py', '_binary.py', '__pycache__', 'ImageQt.py', 'Hdf5StubImagePlugin.py', 'PalmImagePlugin.py', 'ImagePalette.py', 'WebPImagePlugin.py', 'ImageFont.py', 'ImagePath.py', 'TiffTags.py', 'ImImagePlugin.py', 'ImageWin.py', 'ImageFilter.py', '__init__.py', 'SgiImagePlugin.py', 'ImageTk.py', 'ImageMath.py', 'GdImageFile.py', 'WmfImagePlugin.py', 'PcfFontFile.py', 'ImageGrab.py', 'PdfImagePlugin.py', 'IptcImagePlugin.py', 'ImtImagePlugin.py', 'MpegImagePlugin.py', 'MicImagePlugin.py', 'Image.py', 'PcxImagePlugin.py'] 

你們可以幫忙嗎?我完全不確定,這讓我困惑了幾天。我在想,MAYBE Ubuntu的python3-tk軟件包是不完整的,但我不能看到這種情況。 pip的枕頭也一樣。有任何想法嗎?

回答

9

因此,在GitHub上發佈問題後,我被告知我錯過了一些圖書館。

具體而言,我需要

sudo apt-get install tk8.5-dev tcl8.5-dev

然後

pip install -I pillow

重建枕頭。這個工作對我的覆盆子PI運行rasbian

+1

幾乎爲我工作。我用'sudo pip install pillow --upgrade'來代替'pip install -I pillow',它什麼也沒做,然後它就起作用了。 – Metaxal

+0

枕頭現在使用tk8.6,所以更新的修復程序是:'sudo apt-get install tk8.6-dev tcl8.6-dev'然後枕頭重新安裝 – 7yl4r

+0

我必須添加'--no-cache-dir' 'pip install'命令,顯然pip的緩存爲Pillow不知何故是不正確的。 – rednaw

1

我沒有代表發表意見,所以我會回答,而不是

努力時,我也漸漸使用python3錯誤can't from PIL import _imagingtk 對Linux Mint的17 做一個tk_im = ImageTk(im)

首先,我安裝了tk8.6-dev的和tcl8.6-dev的上述

然後我嘗試了pip3 --upgrade route的建議,這並沒有解決問題

如果我在一個shell中導入PIL,PIL.PILLOW_VERSION是2.7.0。 然而,使用pip3列表聲稱是2.3.0。

所以我也sudo pip3 uninstall pillow,其次是 sudo pip3 install pillow

現在的閱讀版本兩種方法返回2.7。0 和程序的作品!

什麼時候/如何抓住枕頭2.3,爲什麼它不會用pip升級,爲什麼它在2.7中顯示爲python shell我不知道,但uninstall/install修正了它。

2

我一直在努力。這些解決方案沒有一個適用於我,其他人都是敵對的,聲稱這個問題已經被解決,同時指向python2.7而不是python3,或者我不能按照說明操作。但在Ubuntu與多臺電腦,我有這個問題,這裏的如何我終於解決了它:

sudo apt-get purge python3-pil; 
sudo apt-get install python3-pil python3-pil.imagetk 

所以基本上將其關閉並重新打開它的貼切版本。 :/