Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python is not configured for tkinter #122

Closed
jstewmon opened this issue Jun 29, 2016 · 13 comments · Fixed by #127
Closed

python is not configured for tkinter #122

jstewmon opened this issue Jun 29, 2016 · 13 comments · Fixed by #127

Comments

@jstewmon
Copy link

Is tkinter purposefully omitted? It seems like the only way to enable it is to rebuild from source.

Adding apt-get update && apt-get install -y --no-install-recommends tk-dev && rm -r /var/lib/apt/lists/* to the current Dockerfiles appears to resolve the issue, but adds ~20MB to the resulting image.

Current behavior:

$ docker run --rm -it python:3.5 python -m tkinter
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/runpy.py", line 174, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/local/lib/python3.5/runpy.py", line 133, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/local/lib/python3.5/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/usr/local/lib/python3.5/tkinter/__init__.py", line 35, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'

$ docker run --rm -it python:2.7 python -m Tkinter
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
jstewmon pushed a commit to jstewmon/pyinstaller that referenced this issue Jun 30, 2016
jstewmon pushed a commit to jstewmon/pyinstaller that referenced this issue Jun 30, 2016
@jstewmon
Copy link
Author

@tianon @yosifkit any thoughts on this? I can submit a PR if there's no objection to adding tk to the official images. I think the -dev package is required for the build, and the lib is required for the runtime.

My plan to fix would be to install tk and tk-dev from the apt/apk, removing tk-dev after the building python.

@kevin-brown
Copy link

99% of Docker files shouldn't need the Tkinter files, as Docker isn't designed to handle GUIs (I believe, correct me if I'm wrong).

You should be able to install Tkinter in a separate Dockerfile that extends the Python ones provided here.

FROM python:3.5

RUN apt-get update && apt-get install tk-dev && rm -r /var/lib/apt/lists/*

@jstewmon
Copy link
Author

@kevin-brown the tkinter module is defined CPython and is complied into python.

https://wiki.python.org/moin/TkInter

I'm not aware of any other way to build/install it as an so.

@yosifkit
Copy link
Member

Since this must be complied into python and cannot be added later, I propose a possible solution to emphasize the "include everything" default tag vs the tiny slim and alpine tags:

  1. Install tk-dev tk tcl-dev tcl during install so that tkinter is compiled in to python.
    1. remove tk-dev tcl-dev in the non-slim and non-alpine variants
    2. remove tk-dev tk tcl-dev tcl in slim and alpine to save space
      • users of these two varints that want to use tkinter can apt-get update && apt-get install tk tcl (or appropriate alpine apk add)

      • I tested this on the 2.7-slim image and it worked fine

        $ docker run --rm -it python:2.7-slim python -m Tkinter
        ...
        ImportError: libtk8.6.so: cannot open shared object file: No such file or directory
        $ docker run --rm -it python:2.7-slim bash -c 'apt-get update && apt-get install -y tcl tk && python -m Tkinter'
        ...
        _tkinter.TclError: no display name and no $DISPLAY environment variable

Size differences:

# current
python              2.7.12-slim         840fa73abd8a        7 days ago          184.1 MB
python              2.7.12              774abfa592f5        7 days ago          665.2 MB
# new
python              2.7-slim            29cb1e9fce53        3 seconds ago       186.1 MB
python              2.7                 9b682a8110bf        38 minutes ago      673 MB

@tianon
Copy link
Member

tianon commented Jul 15, 2016 via email

@jstewmon
Copy link
Author

@yosifkit thanks for the great suggestion! I've implemented your proposal in #127 .

@brando90
Copy link

brando90 commented Oct 6, 2017

so whats the solution? How do we get the library we need?

@brando90
Copy link

brando90 commented Oct 6, 2017

whats wrong with

apt install python3-tk

@yosifkit
Copy link
Member

yosifkit commented Oct 6, 2017

@brando90,

whats wrong with

apt install python3-tk

We don't use the Debian/apt-provided python, but compile and install it from upstream source directly. The python3-tk package is built for the Debian python3 (which may or may not be the same version of python as the one built in the image) and also would pull in python3 from Debian and you would end up with two versions of python3 in the image.

@brando90
Copy link

brando90 commented Oct 6, 2017

@yosifkit how do I do that?

@yosifkit
Copy link
Member

yosifkit commented Oct 6, 2017

@brando90, it is already installed: #127 (comment). If you need help getting it to connect to your display, it'd be better to post questions like that in the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

@Aburt0071

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants