I got problems with importing tkinter
after installing Python version 3.4.2 with pyenv
. My system Python is version 2.7.6. I am using Ubuntu 14.04. For the following sample 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
installed Python version 3.4.2 in ~/.pyenv/versions/3.4.2/
.
The simplest method to install Tkinter in a Windows environment is to download and install either ActivePython 3.8 or 3.7 from here. Alternatively, you can create and activate a Conda environment with Python 3.7 or greater that is integrated with the latest version of Tkinter.
In order to work with a tkinter application, we have to install and import the tkinter library in our environment. Generally, we import the tkinter library in the environment by using from tkinter import * command. The significance of "import *" represents all the functions and built-in modules in the tkinter library.
This problem seems to be solved now using the approach described in this post:
pyenv uninstall 3.4.2
, thensudo apt-get install tk-dev
pyenv install 3.4.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With