【问题标题】:PIL.ImageTk import and/or installation errorPIL.ImageTk 导入和/或安装错误
【发布时间】:2018-10-08 07:40:58
【问题描述】:

当我到达我心爱的 Spyder 控制台时,它欢迎我

Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
Type "copyright", "credits" or "license" for more information.

IPython 2.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

我继续输入:

In [1]: from PIL import Image

然后它会显示另一行,就像一切都正确一样。 然后,在下一行,我输入:

In [2]: from PIL import ImageTk

它返回这个:

Traceback (most recent call last):

  File "<ipython-input-2-47edf18ebb7f>", line 1, in <module>
    from PIL import ImageTk

ImportError: cannot import name ImageTk

好的,这意味着我的库应该有问题。没有汗水。 一位程序员同事遇到了类似的错误here,并且:

  1. 我确信我的导入中没有拼写错误
  2. Ubuntu 报告 python-imaging 包是最新的:
  3. Ubuntu 在 python-imaging-tk 包中报告以下内容:

这些 Bash 行:

python-imaging is already the newest version (3.1.2-0ubuntu1.1).

<more bash lines />

The following packages have unmet dependencies:
 python-imaging-tk : Depends: python-imaging (= 1.1.7-4) but 3.1.2-0ubuntu1.1 is to be installed

这是最有趣的部分。当我返回 Spyder 并键入以获取 PIL.Image 的版本时,它会返回:

In [3]: Image.VERSION
Out[3]: '1.1.7'

我在这里不知所措。请发送帮助。

【问题讨论】:

    标签: python-2.7 ipython python-imaging-library python-import importerror


    【解决方案1】:

    做一个

    sudo apt-get install python-imaging=1.1.7-4
    

    然后

    sudo apt-get install python-imaging-tk
    

    解决了问题。

    它仍然困扰着我为什么,但至少我的依赖项现在正在工作。

    【讨论】:

      【解决方案2】:
      sudo apt-get install python-imaging-tk
      

      这刚刚解决了我的问题。这适用于 python 2.7

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-12
        • 1970-01-01
        • 1970-01-01
        • 2014-06-28
        • 1970-01-01
        • 1970-01-01
        • 2021-11-01
        • 1970-01-01
        相关资源
        最近更新 更多