My Idle is throwing errors that and says tkinter
can't be imported.
Is there a simple way to install tkinter
via pip
or easy_install
?
There seem to be a lot of package names flying around for this...
This and other assorted variations with tkinter-pypy
aren't working.
pip install python-tk
I'm on Windows with Python 2.7 and I don't have apt-get
or other system package managers.
This question is related to
python
python-2.7
tkinter
pip
easy-install
I had the similar problem with Win-8 and python-3.4 32 bit , I got it resolved by downloading same version from python.org .
Next step will be to hit the repair button and Install the Tk/tkinter Package or Just hit the repair. Now should get Python34/Lib/tkinter Module present. The import tkinter should work ..
When you install python for Windows, use the standard option or install everything it asks. I got the error because I deselected tcl.
I'm posting as the top answer requotes the documentation which I didn't find useful.
tkinter comes packaged with python install on windows IFF you select it during the install window.
The solution is to repair the installation (via uninstall GUI is fine), and select to install tk this time. You may need to point at or redownload the binary in this process. Downloading directly from activestate did not work for me.
This is a common problem people have on windows as it's easy to not want to install TCL/TK if you don't know what it is, but Matplotlib etc require it.
If you are using virtualenv, it is fine to install tkinter using sudo apt-get install python-tk
(python2), sudo apt-get install python3-tk
(python3), and and it will work fine in the virtual environment
Inside cmd
, run command pip install tk
and Tkinter should install.
Easiest way to do this:
cd C:\Users\%User%\AppData\Local\Programs\Python\Python37\Scripts>
pip install pythonds
In python, Tkinter was a default package, you can repair the installation and select Tcl/Tk. When you run this, DDL should be installed like so:
if your using python 3.4.1 just write this line from tkinter import *
this will put everything in the module into the default namespace of your program. in fact instead of referring to say a button like tkinter.Button
you just type Button
Had the same problem in Linux. This solved it. (I'm on Debian 9 derived Bunsen Helium)
$ sudo apt-get install python3-tk
I came here looking for an answer to this same question and none of the answers above actually answer the question at all!
So after some investigation I found out: there is a package (for python 3.x at least):
pip3 install pytk
The problem is, it is only the python part of the equation and doesn't install the tkinter libraries in your OS, so the answer is that you can't install it completely via pip https://tkdocs.com/tutorial/install.html
Personally I find this very annoying as i'm packaging a python application to be installed via pip that uses tkinter and I was looking for a way to have pip ensure that tkinter is installed and the answer is I can't I have to instruct users to install it if it's not installed already, a very poor experience for end users who should not need to know or care what tkinter is to use my application.
The Tkinter library is built-in with every Python installation. And since you are on Windows, I believe you installed Python through the binaries on their website?
If so, Then most probably you are typing the command wrong. It should be:
import Tkinter as tk
Note the capital T at the beginning of Tkinter.
For Python 3,
import tkinter as tk
Source: Stackoverflow.com