5

I get this error when I run my python script in my docker image

ImportError: No module named _tkinter, please install the python-tk package

So I tried 'pip install python-tk'

root@43d2222b15c8:/tf_files# pip install python-tk
Collecting python-tk
  Could not find a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk

But that does not fix my issue.

Can you please tell me how can I fix my issue?

Thank you.

n179911
  • 19,547
  • 46
  • 120
  • 162
  • 3
    This topic is similar to your problem. Check pls. https://stackoverflow.com/questions/4783810/install-tkinter-for-python – Tolgahan ÜZÜN Jul 24 '17 at 21:39
  • i tried both apt-get install python3-tk and apt-get install python-tk. Both said no installation candidate. And I am doing that in a docker image. Will that make a difference? – n179911 Jul 25 '17 at 07:09
  • what's base image did you use ? Try ubuntu please. and use ap-get install python-tk. – Yang Yu Aug 28 '17 at 02:16
  • related question: https://stackoverflow.com/questions/46613117/why-does-conda-install-tk-not-work-in-my-docker-container-even-though-it-says-it – Charlie Parker Oct 06 '17 at 20:03
  • `python-tk` is a system package, not a Python package. It cannot be installed using `pip`. – Karl Knechtel Apr 29 '23 at 01:01

2 Answers2

-1

Use import Tkinter. It should not be required via pip. It's built into python2.7 (Assuming you are using python2.7 since this post is tagged with it. If you are using 3 then it's a different solution and what the people in comments are referencing.)

https://docs.python.org/2/library/tkinter.html#module-Tkinter

Holden Rehg
  • 917
  • 5
  • 10
-1

It is probably not a problem with the package not being installed but rather not running because of lack of display.

For convenience I'm pasting the code how to do that:

docker run -ti -e DISPLAY=$DISPLAY blah-image blah-command

Extracted from here: Python Tkinter in Docker .TclError: couldn't connect to display