1

I connected to the remote server (google cloud VM instance - Centos7) with PyCharm from my Windows computer and wanted to execute the code using the remote computer's python3.8.8 via PyCharm. However, I got the error that says

File "/usr/local/lib/python3.8/tkinter/init.py", line 36, in

import _tkinter # If this fails your Python may not be configured for Tk

ModuleNotFoundError: No module named '_tkinter'

I tried to do some different pip installs (pip install python3-tkinter, pip install python3-tk, pip install python3.8-tkinter, etc.) and output of

"pip install python3-tkinter" is

Package python3-tkinter-3.6.8-18.el7.x86_64 already installed and latest version Nothing to do.

Is this tkinter for python3.6?

How can I fix this error?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
ufukyılmaz
  • 51
  • 1
  • 6
  • why the underscore `_tkinter` ? This link might be useful (i think i used it when installing the same): https://stackoverflow.com/questions/20044559/how-to-pip-or-easy-install-tkinter-on-windows. – D.L Feb 24 '22 at 15:00
  • 1
    @D.L: `_tkinter` is a compiled module that is part of the tkinter package. It contains the low-level code that interfaces with the tcl/tk interpreter. – Bryan Oakley Feb 24 '22 at 15:17
  • @BryanOakley: thanks, presumably this means that it is not installed on the host. I posted an answer, but you are welcome to edit or comment on it further. – D.L Feb 24 '22 at 15:22
  • Normally Python libraries are installed in `/usr/lib`, but the error is `/usr/local/lib`. Where is the Python binary (use `which python3` to check)? – acw1668 Feb 24 '22 at 15:29
  • 1
    if you run code on `remote server` then you need `tkinter` installed on this server. But problem is that `tkinter` will try to run on server and display on monitor directly connected to server. And it will need `XWindows` on server to display windows. But servers usually don't have `XWindows` (because they don't need it - they don't even have monitors) and they may not have installed `tkinter` (because it can't be used without `XWindows` and monitor). As I remeber sometimes Ubuntu Servers may have installed `Python` without `tkitner`. – furas Feb 24 '22 at 19:41
  • Does this answer your question? [Why does tkinter (or turtle) seem to be missing or broken? Shouldn't it be part of the standard library?](https://stackoverflow.com/questions/76105218/why-does-tkinter-or-turtle-seem-to-be-missing-or-broken-shouldnt-it-be-part) – Karl Knechtel Apr 29 '23 at 01:48
  • "I tried to do some different pip installs" - Tkinter **cannot be installed with Pip**. If the Python you are trying to use is in /usr/local/lib, then it is not the system Python, meaning that system packages (e.g. `sudo apt-get python3-tk`) will also not fix the problem. You need to re-compile the Python in question with Tkinter support. Please see the linked duplicate for details. – Karl Knechtel Apr 29 '23 at 01:50
  • Aside from that, remoting into another computer and expecting GUI libraries to work is a bit of a problem. First off - where are you expecting the window to show up? – Karl Knechtel Apr 29 '23 at 01:51

0 Answers0