首页 > 解决方案 > 我无法安装 Tkinter 或 tkinter。我尝试了所有代码并重新安装了 TCL/TK。但是还是报错

问题描述

我在 stackover 和许多其他网站上尝试了所有解决方案。但它仍然给出同样的错误。我什至无法安装它。

C:\Users\***\Google Drive\Python>pip install tkinter
Collecting tkinter
  Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter

C:\Users\***\Google Drive\Python>pip install Tkinter
Collecting Tkinter
  Could not find a version that satisfies the requirement Tkinter (from versions: )
No matching distribution found for Tkinter

C:\Users\***\Google Drive\Python>pip install Tk
Collecting Tk
  Could not find a version that satisfies the requirement Tk (from versions: )
No matching distribution found for Tk

C:\Users\***\Google Drive\Python>pip install tk
Collecting tk
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'Varolan bir bağlantı uzaktaki bir ana bilgisayar tarafından zorla kapatıldı', None, 10054, None))': /simple/tk/
  Could not find a version that satisfies the requirement tk (from versions: )
No matching distribution found for tk

C:\Users\***\Google Drive\Python>pip install python3-tk
Collecting python3-tk
  Could not find a version that satisfies the requirement python3-tk (from versions: )
No matching distribution found for python3-tk

标签: pythonpython-3.xtkinter

解决方案


看起来你在 Windows 上,在这种情况下你已经有 tkinter(如果你运行 2.7 或更高版本)。看来你使用 Python 3 所以运行import tkinter. 请参阅文档

如果您使用的是 Linux/Mac/类似变体,那么您需要运行sudo apt-get install python3-tk. 它不是一个pip包,不能以这种方式安装。

如果该python -m tkinter命令在 Windows 上失败,则说明您的安装已损坏,或者如果在 Linux/Mac/Similar 上,则上述命令应该可以工作。


在 Windows 上,有两件事可能出错:

  • 您的安装已损坏
  • 您忘记检查 tkinter 的选项

如果您的安装被破坏,那么重新安装应该可以工作,但是您更有可能在安装时忘记检查该tck/tk and IDLE选项。要检查或安装,请重新运行安装程序并按modify。您应该会看到如下所示的框。然后确保tck/tk and IDLE确实有一个勾号:

在此处输入图像描述

并按下Next


推荐阅读