Can't import tkinter after installing Python 3 with pyenv
I'm having trouble importing tkinter
after installing Python version 3.4.2 with pyenv
. My Python system is version 2.7.6. I am using Ubuntu 14.04. For the following example script t.py
:
import _tkinter
print ("Hello")
I get:
$ pyenv global system
$ python --version
Python 2.7.6
$ python t.py
Hello
$ pyenv global 3.4.2
$ python --version
Python 3.4.2
$ python t.py
Traceback (most recent call last):
File "t.py", line 3, in <module>
import _tkinter
ImportError: No module named '_tkinter'
Traceback (most recent call last):
File "t.py", line 3, in <module>
import _tkinter
ImportError: No module named '_tkinter'
Note that pyenv
Python 3.4.2 is installed in ~/.pyenv/versions/3.4.2/
.
source to share
Change your code to:
import tkinter
Documentation link :
In most cases tkinter is all you really need, but a number of additional modules are also available. The Tk interface is located in a binary module named _tkinter. This module contains a low-level interface to Tk and should never be used directly by application programmers. This is usually a shared library (or DLL), but in some cases it can be statically linked to the Python interpreter.
source to share