38

I am trying to add a GUI input box and I found out that the way you do that is by using a module called tkinter. While I was trying to install it on my arch linux machine through the ActivePython package I got the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: libtk8.6.so: cannot open shared object file: No such file or directory

shell returned 1\
vvvvv
  • 25,404
  • 19
  • 49
  • 81
KnownAsDon
  • 1,365
  • 1
  • 8
  • 14
  • 1
    _"`import _tkinter # If this fails your Python may not be configured for Tk`"_ so I guess we at least know what the problem is. – Nae Jan 29 '18 at 15:40
  • _"...I tried to fit this into the as least lines as possible..."_ While this may be true that you tried, it does _not_ mean that above post has a code piece that fits the required [mcve]. You need to provide the code part as well to reproduce that error. – Nae Jan 29 '18 at 15:44
  • I dont undestand what you mean... – KnownAsDon Jan 29 '18 at 15:45
  • 1
    What produces the above error? `import tkinter` line alone? – Nae Jan 29 '18 at 15:46
  • Yup, I just tried to delete everything and i get the same output – KnownAsDon Jan 29 '18 at 15:49
  • Please provide that as well then. As in I tried `import tkinter` and I got the error : `...`. At which point I think it's a perfect post. – Nae Jan 29 '18 at 15:50
  • Alredy found the answer bro...thanks anyways...how do i mark this post as solved now? – KnownAsDon Jan 29 '18 at 15:56
  • You can mark your own answer, but it may require a certain period of time before you can. – Nae Jan 29 '18 at 16:04
  • 2
    If you've found the answer, it doesn't necessarily mean your question is garbage now. You can still edit the question for improvement, so that others can easily reach the same information later. – Nae Jan 29 '18 at 16:06
  • Related : https://stackoverflow.com/q/5459444/7032856 – Nae Jan 30 '18 at 03:10

4 Answers4

85

All you need to do is to install the tkinter package. Now universal precompiled packages such as ActivePython will not work, well at least it didn't work for me. I don't know if this problem occurs in other OSes but I know the solution for Linux: install the Tk package from a repository.

In Arch, Tk is available in the Arch repository. You don't need aur for this, just type on the terminal:

sudo pacman -S tk

If you are on a Debian, Ubuntu or another Debian-based distro, just type on the terminal:

sudo apt-get install tk

On Fedora:

sudo dnf install tk

Tk is not to be mistaken with python-tk, which is a package for Python 2 (you shouldn't need it unless you are working with legacy code).

Isa
  • 31
  • 6
KnownAsDon
  • 1,365
  • 1
  • 8
  • 14
10

Install tk through command line

sudo pacman -S tk
sudo apt-get install tk

depending on your OS. It will work.

import tk

or

import turtle  # (turtle uses tk as a dependancy)

reproduces the error.

Also doing pip install does not removes the error. So you must install tk through your package manager like mentioned above.

Prajjwal Datir
  • 123
  • 1
  • 7
4

I'm on Manjaro, use Gnome3 on Wayland. After installed tk I got an error about Xorg. So I use Google, and found I need to install python-pygubu from Visual editor for creating GUI in Python 3 tkinter.

And then another error like: Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine". Also found a solution, to install gtk-engine-murrine form that link.

roachsinai
  • 527
  • 5
  • 14
3

If you happen to be working with Alpine then the below command will install tk.

apk add tk
JSuar
  • 21,056
  • 4
  • 39
  • 83