问题
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.
回答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
回答2:
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
来源:https://stackoverflow.com/questions/45289891/how-to-install-python-tk-in-my-docker-image