【发布时间】:2016-10-03 02:06:08
【问题描述】:
问题:如何让 dpkg PIL/Pillow 版本与 python3.5 和 python3-tk 一起使用?
问题:更新后重启系统后,调用 PIL 方法的 python3.5 tkinter 代码不再有效。错误信息是:
Traceback (most recent call last):
File "/home/user1/.local/lib/python3.5/site-packages/PIL/ImageTk.py", line 176, 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/user1/Code/tkTreeview_test.py", line 37, in <module>
app = App(root, path=path_to_my_project)
File "/home/user1/Code/tkTreeview_test.py", line 22, in __init__
self.root_pic2 = ImageTk.PhotoImage(root_pic1)
File "/home/user1/.local/lib/python3.5/site-packages/PIL/ImageTk.py", line 115, in __init__
self.paste(image)
File "/home/user1/.local/lib/python3.5/site-packages/PIL/ImageTk.py", line 180, in paste
from PIL import _imagingtk
ImportError: cannot import name '_imagingtk'
在阅读了类似的问题(例如1,2,3)并查看错误消息后,我认为上述错误消息与我的.local中的PIL.ImageTk和Tcl之间的通信问题有关/lib/python3.5/site-packages/PIL 文件夹。
我使用 Synaptic 包管理器清除了 python3-pil、python3-pil.imagetk 和 python3-tk 并再次重新安装它们。另外,我尝试重新安装 tk8.6 和 tcl8.6。但是,每次通过 PIL.ImageTk 模块运行打开图像的代码时,相同的错误消息仍然存在。
另外,我检查了我可以使用 python3-tk 中的 tkinter.PhotoImage(file=i) 打开图像文件。图像显示没有任何错误消息。但是,我使用 PIL.ImageTk.PhotoImage(i) 打开相同的图像文件 i,我的代码失败并出现上述错误消息。
已安装的 dpkg 包:
ii libtcl8.6:amd64 8.6.5+dfsg-2 amd64 Tcl (the Tool Command Language) v8.6 - run-time library files
ii tcl 8.6.0+9 amd64 Tool Command Language (default version) - shell
ii tcl8.6 8.6.5+dfsg-2 amd64 Tcl (the Tool Command Language) v8.6 - shell
ii libtk8.6:amd64 8.6.5-1 amd64 Tk toolkit for Tcl and X11 v8.6 - run-time files
ii tk8.6 8.6.5-1 amd64 Tk toolkit for Tcl and X11 v8.6 - windowing shell
ii tk8.6-blt2.5 2.5.3+dfsg-3 amd64 graphics extension library for Tcl/Tk - library
ii python3-tk 3.5.1-1 amd64 Tkinter - Writing Tk applications with Python 3.x
ii python3-pil:amd64 3.1.2-0ubuntu1 amd64 Python Imaging Library (Python3)
ii python3-pil.imagetk:amd64 3.1.2-0ubuntu1 amd64 Python Imaging Library - ImageTk Module (Python3)
ii python3-pilkit 1.1.13+dfsg-1 all Utilities and processors built for, and on top of PIL (Python3 version)
已安装的 pip 包: 使用 pip list 和 pip3 list,我找到了 pilkit (1.1.13) 和 Pillow (3.2.0)安装。这意味着我通过 pip 在我的系统中安装了 Pillow (3.2.0),并通过 dpkg 安装了 python3-pil:amd64 版本 3.1.2-0ubuntu1。它们的共存是否会导致冲突,从而导致我的问题?
我被这个问题所困扰,并感谢有关克服上述错误消息的建议。谢谢
【问题讨论】:
-
试试这个
sudo apt-get install python-imaging-tk -
我正在使用 python3.5 我应该使用 sudo apt-get install python3-imaging-tk 吗?在我的系统上,python 默认为 python2.7。
-
@shivsn 注意,选择 'python-pil.imagetk' 而不是 'python-imaging-tk' python-pil.imagetk 已经是最新版本(3.1.2-0ubuntu1)。 0 升级,0 新安装,0 删除,0 不升级。我的问题没有改善。
标签: tkinter pip tcl python-imaging-library python-3.5