无法在我的 ubuntu 机器 16.04 上安装 python3-tk

无法在我的 ubuntu 机器 16.04 上安装 python3-tk

我正在尝试使用 pycharm 中的 tkinter 制作第一个桌面应用程序。

from tkinter import *

root = Tk()
mLabel = Label(root, text="This is Header")
mLabel.pack
mLabel.mainloop()

但我有一个例外说

ImportError: No module named '_tkinter', please install the python3-tk package

我尝试像这样安装 python3-tk

sudo apt-get install python3-tk

但后来我得到了一个错误install-info

ronem:::ronem:~$ sudo apt-get install python3-tk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
libfftw3-single3:i386 libgomp1:i386 libpam-systemd:i386 
libpulsedsp:i386 libtdb1:i386
libwebrtc-audio-processing-0:i386
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
blt tk8.6-blt2.5
Suggested packages:
blt-demo tix python3-tk-dbg
The following NEW packages will be installed:
blt python3-tk tk8.6-blt2.5
0 upgraded, 3 newly installed, 0 to remove and 437 not upgraded.
1 not fully installed or removed.
Need to get 0 B/604 kB of archives.
After this operation, 2,117 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up install-info (6.1.0.dfsg.1-5) ...
/usr/sbin/update-info-dir: 3: /etc/environment: CLASSPATH: not found
dpkg: error processing package install-info (--configure):
subprocess installed post-installation script returned error exit 
status 127
Errors were encountered while processing:
install-info
E: Sub-process /usr/bin/dpkg returned an error code (1)
ronem:::ronem:~$ 

请指导我解决我遗漏的问题

答案1

打开终端并输入:

cat /etc/environment  

检查 中是否有一行包含不属于 的/etc/environment字符串。您应该注释掉 中的所有内容,除了第一行( 的设置以 开头),方法是在每行前面添加一个字符。使用以下命令在 nano 文本编辑器中打开文件进行编辑:CLASSPATH/etc/environment/etc/environmentPATHPATH=#/etc/environment

sudo nano /etc/environment  

Nano 编辑器键盘快捷键
使用键盘组合键Ctrl+O然后按 将Enter文件保存到当前位置。
使用键盘组合键Ctrl+X退出 nano。

相关内容