Python3 ImportError:没有名为'_tkinter'的模块

时间:2017-05-21 20:53:52

标签: python python-3.x tkinter

在我的Linux Mint 18上,我尝试在3.5.2旁边安装Python 3.6.1。 使用这些命令:

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
tar xJf Python-3.6.1.tar.xz 
cd Python-3.6.1 
./configure 
make 
make install

安装成功但是,现在,每次我尝试导入tkinter时,我都有同样的错误:

>>> from tkinter import tk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/tkinter/__init__.py", line 35, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'

我不知道如何摆脱这个问题,以及如何删除3.6.1

3 个答案:

答案 0 :(得分:11)

我认为你仍然需要安装tkinker包。您只需输入以下内容即可完成此操作:

sudo apt-get install python3-tk

答案 1 :(得分:2)

The issue as I see is that you are still calling your python3.5 binaries which might be set as default python interface. See the line in your error which tells the version of python it is referring to:

/usr/local/lib/python3.5/tkinter/

If it's a UNIX / Linux flavour you are using, you can check where are your python binaries by using

whereis python

and you will get a list of all the flavours and places it is in:

You simply call out your chosen flavor to work with, which I am guessing might be

/usr/local/bin/python3.6

and then list the available modules to check if Tkinter is available or not, although it is highly unlikely not to as it comes bundled as a standard library.

答案 2 :(得分:-1)

如果您使用的是pycharm,则只需编写以下内容:

从tkinter导入*