0

I am trying to run some plotting libraries that use Tkinter. I am using Python 2.7, and am getting the exact error (capitalization important :))

ImportError: No module named Tkinter

Seems like a lot of people are running into a similar issue that is solved by making sure to use the capitalized Tkinter versus all lowercase tkinter. I do not believe this is my problem since it is in fact capitalized.

When I run:

python --version

I get:

Python 2.7.5

Is there a place I can check to make sure Tkinter is properly installed? Has anyone else seen this particular issue with Python 2.7?

khelwood
  • 55,782
  • 14
  • 81
  • 108
cooke
  • 192
  • 2
  • 13
  • Are you using windows, as Tkinter only comes per standard with the python files for windows. If using linux, then `apt install python-tk` will install it. – SolarFactories Jul 14 '17 at 14:27

1 Answers1

-1

First, run pip freeze from the directory you want to use it. If you use a virtual environment, make sure that's active. This will show you all packages currently installed

The more exact option is to check the site-packages where they get installed (I use ipython):

How do I find the location of my Python site-packages directory?

$ ipython

In [1]: import site

In [2]: site.getsitepackages()
Out[2]: 
['/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages',
 '/Library/Python/3.6/site-packages']

then go there:

cchilders:/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages 
$ ls
IPython                 jupyter_client              python_dateutil-2.6.0.dist-info
Jinja2-2.9.6.dist-info          jupyter_client-5.0.1.dist-info      pytz
MarkupSafe-1.0.dist-info        jupyter_console             pytz-2017.2.dist-info
Pygments-2.2.0.dist-info        jupyter_console-5.1.0.dist-info     pyzmq-16.0.2.dist-info
__pycache__             jupyter_core                qtconsole
appnope                 jupyter_core-4.3.0.dist-info        qtconsole-4.3.0.dist-info
...etc...

The same things you saw on pip freeze should show up here.

Make sure you have the package for the right version of python. If using python 3, you have to say:

pip3 freeze

But apparently the safest way to install is using apt if you have linux:

sudo apt-get install python-tk

Install tkinter for Python

codyc4321
  • 9,014
  • 22
  • 92
  • 165
  • Almost all of this is wrong, because Tkinter - being **part of the standard library** - should not ever be expected to be found in the `site-packages` directory. It **cannot be installed using Pip**, and checking for its presence is not Pip's responsibility. – Karl Knechtel Apr 29 '23 at 01:15