No module named 'tkinter'

I can import tkinter from a python command line in a terminal, but when I try to import it in PyCharm I get "ModuleNotFoundError: No module named 'tkinter'." 

When I run `python3 -m tkinter` from the terminal, I get the sample window.

In the terminal I running version 3.6.8.  In PyCharm, the Python version is 3.7.4.   I can't seem to change the interpreter to 3.6.8... or install tkinter for version 3.7.4.

Can someone please give me some help with this?

7 comments
Comment actions Permalink

Hi,

What's the difficulty with configuring your Python 3.6.8 in PyCharm?

0
Comment actions Permalink

I don't know... I assume I'm doing something wrong, but every time I try, it's still using version 3.7.4.

From my terminal, I typed "which Python3" and it returned "/user/bin/python3" and "python3 --version" returns "Python 3.6.8."

I set up a new virtual environment in PyCharm ("my_venv") and selected "/user/bin/python3" as the Base interpreter. I checked "Inherit global site-packages" and "make available to all projects."  Then I applied it, and restarted PyCharm.

When I go to the terminal in PyCharm and check "python --version" from the (my_venv) prompt it says "Python 3.7.4."

So, something isn't working when I try to set up Python 3.6.8 in PyCharm.  Am I missing something?

Thanks!

0
Comment actions Permalink

That's interesting. You do everything right.

Are there any symlinks for that interpreter?

How does it go if you configure /user/bin/python3 as a System Interpreter in PyCharm? https://www.jetbrains.com/help/pycharm/configuring-local-python-interpreters.html

0
Comment actions Permalink

Thank you for the suggestion, but it's still version 3.7.4.

In my /usr/bin folder I have python3, python3.7 and python3.7m.

Oddly, the "Project Interpreter" shows the Python icon, then "Python 3.7 /usr/bin/python" and no matter what I select, the leading "Python 3.7" never changes. 

Still from my terminal "Python3 --version" shows 3.6.8, but in PyCharm it is always 3.7.4.

I must be missing something simple, but I don't see it.  

0
Comment actions Permalink

Sorry... my day job caught up with me and I haven't had time to revisit this.  I finally tried the suggestions in the recommended post.  I found no aliases or hashes for python or python3.  I attempted to clear them, anyway.  It had no effect.  I am still not able to access tkinter from PyCharm.  It still says "ModuleNotFoundError: No module name 'tkinter'."  

I keep trying to point the interpreter to the correct folder: "/user/bin/python3" but when I check in the PyCharm terminal, it tells me it's using version 3.7.4, instead of version 3.6.8 when I use by Linux terminal.  

Is there somewhere else in PyCharm's settings that is overriding the selected interpreter?  Or, is there some reason it would ignore the path I have selected in the interpreter for the virtual environment?

Best,

Robert.

0
Comment actions Permalink

I had the same problem, I tried using a virtualenv environment based on the /usr/bin/python3.6 (python 3.6.9) behind.I installed python-tk package in Ubuntu and didn't changed a thing.

Out of despair, I created a new environment using Anaconda3 (and python 3.7) and it worked, no tkinter problem anymore.

That's when I realized that I needed to install:

> sudo apt install python3-tk

Then the virtualenv environment worked as well. I would say the problem come from dependencies of the base python binary used in your virtual environment. I suggest you install python3-tk (or the equivalent package for your distribution)

TL;DR: Install the python3-tk package because your base python is python3 (not python) and python-tk and python3-tk are two distinct packages.

0

Please sign in to leave a comment.