ImportError: cannot open shared object file: No such file or directory


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/", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: cannot open shared object file: No such file or directory

shell returned 1
Asked By: KnownAsDon



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).

Answered By: KnownAsDon

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.

Answered By: roachsinai

Install tk through command line

sudo pacman -S tk
sudo apt-get install tk

depending on your OS.
It will work.

import tk


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.

Answered By: Prajjwal Datir

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

apk add tk
Answered By: JSuar
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.