Search code examples
pipcentospython-3.6dependency-managementyum

How to make python3 use my pip dependency of tkinter instead of yum tkinter


I'm using python3 tkinter to build a small GUI on Linux Centos I have my environment set up with all the dependencies installed (cython, numpy, panda, etc) When I go to install tkinter

pip3 install tk
$ python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter as tk
>>> No module found: tkinter

I get the above error despite 'pip list' displaying the 'tk' dependency, python still throws the error. The dependency correctly shows up in "site-packages" as well.

But when I use yum to install tkinter

sudo yum install python3-tkinter

and do the same thing

python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter as tk
>>> tkinter._test()

it works perfectly fine.

The issue is that if I want to package all the dependencies together and share it, the working version of tkinter won't be in the package and other users will be confused when they build the project

Why is 'pip install tk' not being recognized as a valid installation of tkinter but 'sudo yum install python3-tkinter' works? All the other dependencies work with pip, it's just tkinter that is broken. How can I make python recognize the pip installation?


Solution

  • Why is 'pip install tk' not being recognized as a valid installation of tkinter but 'sudo yum install python3-tkinter' works?

    Because pip install tk installs an old package called tensorkit, not tkinter. You can't install tkinter with pip.