對於那些誰需要知道,我是運行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的枕頭也一樣。有任何想法嗎?
幾乎爲我工作。我用'sudo pip install pillow --upgrade'來代替'pip install -I pillow',它什麼也沒做,然後它就起作用了。 – Metaxal
枕頭現在使用tk8.6,所以更新的修復程序是:'sudo apt-get install tk8.6-dev tcl8.6-dev'然後枕頭重新安裝 – 7yl4r
我必須添加'--no-cache-dir' 'pip install'命令,顯然pip的緩存爲Pillow不知何故是不正確的。 – rednaw