为python3.4.3配置tkinter问题
我很擅长使用Raspberry Pi,而我正在尝试设置一个简单的GUI应用程序来启动我的Pi。 我使用的是Raspberry Pi3,安装了Python 3.4.3。
当我键入python
:
~$ python Python 3.4.3 |Continuum Analytics, Inc.| (default, Aug 21 2015, 00:53:08) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information.
当我尝试导入tkinter时:
>>> import tkinter Traceback (most recent call last): File "", line 1, in File "/home/pi/miniconda3/lib/python3.4/tkinter/__init__.py", line 38, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named '_tkinter' >>>
所以,我可以看到错误来自miniconda3。 我安装它的唯一原因是使用PyQt5,但是当我尝试使用它时我遇到了类似的错误,所以我切换到了Tkinter,因为有更多的例子将它与pi在线使用。
我已经运行以下命令来尝试安装Tkinter:
sudo apt-get install tk-dev sudo apt-get install tk8.6-dev sudo apt-get install python-imaging-tk sudo apt-get install python-tk sudo apt-get install python3-tk
我怎样才能解决这个问题? 我已经读过一些地方再次make
python,但没有人说如何做到这一点。
多谢你们!
安装Tkinter包以使用Python 3.x编写Tk应用程序。 在所有当前支持的Ubuntu版本中,打开终端并键入:
sudo apt install python3-tk # for Python 2.x install python-tk
然后运行/usr/bin/python3
来启动Ubuntu附带的默认Python 3并import tkinter
将起作用。
-
看来你正在推出带有raspberry-pi发行版的mini-conda python而不是python。 你可以查看输出:
which python
预期输出:
/usr/local/bin/python
或mini-conda自定义安装路径(如果之前已添加)。 -
测试使用绝对路径启动python时Tk是否有效:
/usr/bin/python
-
要完成我的答案,如果你想使用miniconda python,请使用自己的安装方法:
conda install packagename
参考: Miniconda主页 ,:)我不知道tkinter的确切包名。