linux 无法在VSCodium for Pop!_OS中导入tkinter for Python文件

yeotifhr  于 6个月前  发布在  Linux
关注(0)|答案(1)|浏览(65)

我试图为我的Python文件安装tkinter,以便我能够显示GUI窗口。然而,当我试图在VSCodium中运行我的Python文件时,我遇到了这个错误:File "/home/zhenf/VSCodium_Workspace/pyfilereader/fileReader.py", line 4, in <module> import tkinter as tk ModuleNotFoundError: No module named 'tkinter'
我用sudo apt install python3命令下载了我的主文件夹,我的项目文件夹所在的父文件夹,以及我的项目文件夹,我的python文件存储在我的主文件夹和我的项目文件夹中。我在我的主文件夹和项目文件夹中安装了tkinter。当我在Pop!_OS终端上运行python shell时,tkinter工作正常,但当我试图用VSCodium运行python文件时,tkinter不工作。
我该如何解决这个问题?
x1c 0d1x的数据

hi3rlvi2

hi3rlvi21#

可能你使用python2到目前为止,最近移动到python3.如果是这种情况,对于任何命令,你在那里使用命令'python'之前,现在你应该使用python3.例子:从终端运行python在交互模式:

#earlier:

python
>>>

#Now

python3

>>>

#Earlier
#to run python file

python myfile.py

#now
#to run python file
python3 myfile.py

字符串
因为我可以看到你在终端中只输入了python。但即使这样做,你也可能需要安装最新版本的tkinter。你的tkinter可能是旧版本。对我来说,这是通过以下方式安装tkinter解决的:

sudo apt -y install python3-tk python3-pil python3-pil.imagetk


而对于同样的问题。tkinter文档说安装tkinter在以下任何一种方式:它突出了你面临的确切问题。
Install the latest version of tkinter in any of the following ways for this error
希望这是有帮助

相关问题