问题:如何使dpkg PIL/枕头版本与python3.5和python3-tk协同工作?
问题:更新后重新启动系统后的,调用PIL方法的python3.5tkinter代码不再工作。错误信息是:
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/lib/python3.5/site-packages/PIL文件夹中的PIL.ImageTk和Tcl之间的通信问题有关。
我已经使用来清除python3-pil、python3-pil.imagetk和python3-tk并重新安装它们。另外,我尝试重新安装tk8.6和tcl8.6。但是,每次通过PIL.ImageTk模块运行打开图像的代码时,相同的错误消息仍然会持续存在。
另外,我检查了是否可以使用python3-tk中的tkinter.PhotoImage(file=i)来打开图像文件。图像显示任何错误信息。但是,我使用PIL.ImageTk.PhotoImage(i)打开相同的图像文件i,我的代码在上面的错误msg中失败。
安装的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列表和pip3列表,我找到了pilkit (1.1.13)和Pillow (3.2.0)。这意味着我有枕头(3.2.0)通过pip和python3-pil: and 64版本3.1.2-0ubuntu1通过dpkg安装在我的系统中。他们的共存是否导致了冲突,从而导致了我的问题?
我对这个问题很感兴趣,并对克服上面提到的错误msg表示感谢。谢谢
发布于 2016-06-03 09:41:45
回答:,上面报告的错误消息是唯一使用python3.5和tcl/tk 8.6的Pillow(3.2.0) (目前是PIL的最新版本)的。对于PIL.ImageTk.PhotoImage()方法,它不知何故未能正确地与tcl通信。请看我与@Akash的通信,看看我是如何发现的。
为了克服上述错误信息,以便dpkg PIL/Pillow版本(3.1.2)可以再次使用python3.5和python3-tk,我执行了以下操作:
sudo pip3 uninstall Pillow==3.2.0
作为sudo,或
pip3 uninstall Pillow==3.2.0
作为所有者。
要在python2.7中卸载Pillow(3.2.0),我只需运行相同的命令,但将pip3替换为pip。pip3 list | grep Pillow
和Pillow (3.1.2)
。我重新运行了使用PIL.ImageTk.PhotoImage()方法的代码,它们运行起来了。发布于 2016-06-03 06:14:02
我通常使用python虚拟环境,当使用安装在包管理器外部的新包时(synaptic/anaconda)等等。
这很简单,请参考以下文档:
http://docs.python-guide.org/en/latest/dev/virtualenvs/
假设您的项目文件夹是myProject
>> cd myProject
>> virtualenv venv
>> source venv/bin/activate
>> pip install package_name
https://stackoverflow.com/questions/37607051
复制相似问题