LoginSignup
29
17

More than 5 years have passed since last update.

PythonでTkinterがimportできなかった

Posted at

pythonでtkinterがimportできない問題に遭遇したけど、日本語で解決方法が見つからなかったから書く。

環境

Ubuntu16.04 LTS
pyenv 1.0.10-12-gda80a3d
python 3.6.1 (2.7系でも多分同じ)
IPython 6.0.0

原因

pyenvでpythonをインストールしたときに、tk-devがないのが原因だった。

解決方法

> sudo apt-get install tk-dev
> pyenv install x.x.x

python -m tkinterでtkinterのウィンドウが表示されればオッケー。

発生した障害

ipythonで%pasteが使えなくてあれ?となる。
エラーメッセージにtkinterがないと言われる。

調べてみたらこんな感じになった。

import tkinter
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-13f92e9c9d24> in <module>()
----> 1 import _tkinter

ModuleNotFoundError: No module named '_tkinter'

調べたらここにたどりついた。

29
17
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
17