简体   繁体   English

ModuleNotFoundError: 没有名为“tkinter”/PyCharm 的模块

[英]ModuleNotFoundError: No module named 'tkinter' / PyCharm

I am trying to run this code in pycharm:我正在尝试在 pycharm 中运行此代码:

import tkinter as tk

root = tk.Tk()

w = tk.Label(root, text="Hello, world!")
w.pack()

root.mainloop()

However it always gives me the following errror:但是它总是给我以下错误:

Traceback (most recent call last):
  File "/home/nils/PycharmProjects/rfid/first_test.py", line 1, in <module>
    import tkinter as tk
ModuleNotFoundError: No module named 'tkinter'

If I use the same exact code in IDLE, it works perfectly.如果我在 IDLE 中使用完全相同的代码,它可以完美运行。 I just can not figure out how to install/import tkitner (through the project interpreter didnt work).我只是不知道如何安装/导入 tkitner(通过项目解释器不起作用)。 I am using python 3.7 and the newest Linux Mint.我正在使用 python 3.7 和最新的 Linux Mint。

If you could provide me some hints or a solution, it would be very much appreciated :D如果您能给我一些提示或解决方案,我将不胜感激:D

Thanks!谢谢!

Edit: Typing in " import tkinter " in the IDLE shell works fine, however typing in the same in the PyCharm console produces the error above...编辑:在 IDLE shell 中输入“import tkinter”工作正常,但是在 PyCharm 控制台中输入相同的内容会产生上面的错误......

Edit2: I solved the problem by completly uninstalling pycharm and installing it again. Edit2:我通过完全卸载 pycharm 并重新安装它解决了这个问题。

如果您在 macOS Big Sur 上遇到问题并使用 Homebrew,请知道 tkinter 不包含在 Python 3.9 中,需要单独安装。

brew install python-tk@3.9

您可以右键单击它并转到上下文操作进行安装或转到终端并键入 pip install python-tkinter 或 sudo apt install python-tkinter!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM