Tkinter could not be imported in Python

I encountered a problem that tkinter could not be imported in python, but I could not find a solution in Japanese, so I will write it.

environment

Ubuntu16.04 LTS pyenv 1.0.10-12-gda80a3d python 3.6.1 (probably the same for 2.7 series) IPython 6.0.0

Cause

When I installed python with pyenv, it was due to the lack of tk-dev.

Solution

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

It's okay if the tkinter window is displayed with python -m tkinter.

Failure that occurred

I can't use% paste in ipython. The error message says there is no tkinter.

When I looked it up, it looked like this.

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

ModuleNotFoundError: No module named '_tkinter'

After searching, I arrived at here.

Recommended Posts

Tkinter could not be imported in Python
A record that GAMEBOY could not be done in Python. (PYBOY)
[Python] Show multiple windows in Tkinter
GUI creation in python using tkinter 2
A memorandum (masOS) that import tkinter could not be done with python installed from pyenv
33 strings that should not be used as variable names in python
Modules cannot be imported in Python on EC2 run from AWS Lambda
Quadtree in Python --2
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Discord in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
How to use tkinter with python in pyenv
Sqlite in python
StepAIC in Python
Could not import C error in GO environment
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
PyQtGraph may not be available in the interpreter.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Matplotlib etc. cannot be imported in VirtualEnv environment
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
[Python] Tkinter template
Run the output code with tkinter, saying "A, pretending to be B" in python
When "Message: session not created" occurs in Python + Selenium
Japanese can be used with Python in Docker environment
Key input that does not wait for key input in Python
Not being aware of the contents of the data in python
list comprehension because operator.methodcaller cannot be used in python 2.5
[Python] tkinter Code that is likely to be reused
Operators ++,-cannot be used in python (difference from php)
Note that int64 could not be received by pyOSC
Non-linear simultaneous equations can be easily solved in Python.