0

I can't import tkinter, I get the following error message:

ModuleNotFoundError: No module named '_tkinter'

I am using python version 3.8.6 installed using pyenv on a mac. Please help

Bjorn
  • 1
  • You probably didn't have the Tk headers installed when you compiled Python. I'm not sure what the right way to install them is on macOS; on Linux you'd typically install a package provided by the OS vendor, e.g. `tk-dev`. Install those headers and rebuild Python. – ChrisGPT was on strike Nov 29 '20 at 20:02

1 Answers1

0

Try using conda and see if that works. Or before you do that, make an isolated environment where you just install Tk and other necessary packages. Rare, but could me somewhat of a dependency issue

abrer
  • 61
  • 3
  • So I downloaded python using conda and tried that and it worked well, thank you! – Bjorn Nov 29 '20 at 22:19
  • However, now I don't have the other modules that I had previously downloaded and was managing using pyenv. The closest I got is that it's related to the new macOS and pyenv is not yet supported. Because I just realized that I can't even download python using pyenv. Any ideas on what the problem might be or do I just have to wait for an update to pyenv to use that? – Bjorn Nov 29 '20 at 22:20
  • So what you can do is export the old environment into a .yml file. Open that file, and that should tell you all the modules you have installed. Then you can activate your conda env and install those same versions. Conda automatically updates dependencies for most modules so you prolly won’t even need to specify them. I usually specify them when I want to use and older version since conda always updates to the latest version (while keeping a check on dependencies). Let me know if you have any more questions! – abrer Dec 01 '20 at 02:12