2013-07-30 40 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 

所以基本上将其关闭并重新打开它的贴切版本。 :/