I can't import pyton module tkinter in my gitpod workspace.

My .gitpod.Dockerfile contains:

FROM gitpod/workspace-full-vnc
USER root
RUN apt update && apt install -y python-tk python3-tk tk-dev

but when I run my project I get

Traceback (most recent call last):
  File "basic-screen-changer.py", line 1, in <module>
    import tkinter as tk
  File "/home/gitpod/.pyenv/versions/3.8.6/lib/python3.8/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

python --version shows me Python 3.8.6.
Installed packaged are:

itpod /workspace/pydiag $ dpkg -l |grep ^ii |tr -s ' ' |cut -d ' ' -f2,3 |egrep '^python.*tk|^tk'
python-tk 2.7.18-1
python3-tk:amd64 3.8.5-1~20.04.1
tk 8.6.9+1
tk-dev:amd64 8.6.9+1
tk8.6 8.6.10-1
tk8.6-blt2.5 2.5.3+dfsg-4
tk8.6-dev:amd64 8.6.10-1

That problem occurs because the workspace-full-vnc image uses pyenv and the module path is different (source). To use python modules, you need to install them using python2 or python3 -m pip install ....

  • This doesn't work. As pointed at community.gitpod.io, tkinter has to be installed before pyenv, so it needs to be done while building workspace image. – makayabou Jan 16 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.