You are not logged in.

#1 2020-01-29 20:25:05

tuliochiodi
Member
From: Brazil
Registered: 2020-01-29
Posts: 6

Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

Hello people,
This is my first post on the forum, I will try to make it as correct and complete as possible if you have any tips to improve my post I will gladly accept it.
I'm having trouble running code written in Python that uses Tkinter.
I will try to describe in detail my actions to facilitate the identification of the error.
I started a course at Coursera on DSP (Digital Signal Processing) where it is suggested to install a tool written in python (and a little bit of C).

link on Github:
sms-tools Github link

Using pyenv/virtualenv/virtualenvwrapper I created an environment with Python 3.7.5, as recommended in the "How to use" section of the repository.

I installed the required libraries in my environment by pip:

%pip install ipython numpy matplotlib scipy cython 

I compiled some C functions in the "/sms-tools/software/models/utilFunctions_C" directory with the following command:

%python compileModule.py build_ext --inplace 

Finally, I run the models GUI in the directory "/sms-tools/software/models_interface"

%python models_GUI.py

and I get the following message:

 Traceback (most recent call last):
  File "models_GUI.py", line 6, in <module>
    from Tkinter import *   ## notice capitalized T in Tkinter 
ModuleNotFoundError: No module named 'Tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "models_GUI.py", line 9, in <module>
    from tkinter import *   ## notice lowercase 't' in tkinter here
  File "/home/tuliochiodi/.pyenv/versions/3.7.5/lib/python3.7/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter' 

I will now describe some of my attempts to solve the problem:

Looking at Tkinter section in Python Wiki I tried installing Tcl and Tk.

 %sudo pacman -S tk

but it was already installed. after that I tried installing with pip:

%pip install tk

and

%pip install tkinter

and the error remains the same.

I also tried to create a symlink with this code:

 %ln -s /usr/lib/python3.8/lib-dynload/_tkinter.cpython-38-x86_64-linux-gnu.so _tkinter.cpython-38-x86_64-linux-gnu.so 

the symlink was created in the following folders:

 ~/.ve/Coursera_DSP/lib/python3.7/lib-dynload 

and

 .pyenv/versions/3.7.5/lib/python3.7/lib-dynload 

But I still get the same error.

I appreciate if anyone has any suggestions and I apologize for the language errors, since English is not my mother tongue.


smile

Offline

#2 2020-01-29 20:51:00

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

Your venv environment seems outdated, update the env first..

Offline

#3 2020-01-29 21:29:09

tuliochiodi
Member
From: Brazil
Registered: 2020-01-29
Posts: 6

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

qinohe wrote:

Your venv environment seems outdated, update the env first..

Hello qinohe, thank you for your reply!

I think they are up to date

 % virtualenv --version
16.7.9 
% pyenv --version
pyenv 1.2.16 

If you mean that it is out of date because of Python version 3.7.5, that is the version of the environment I created, as the installation guide requires a python v3.7.x.
From https://github.com/MTG/sms-tools:

How to use
In order to use these tools you have to install python (recommended 3.7.x) and the following modules: ipython, numpy, matplotlib, scipy, and cython.


smile

Offline

#4 2020-01-30 00:57:52

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

tuliochiodi wrote:

...
Looking at Tkinter section in Python Wiki I tried installing Tcl and Tk.
...

You also need to install python-pmw [Community] to use the  Tkinter module.

tuliochiodi wrote:
qinohe wrote:

Your venv environment seems outdated, update the env first..

Hello qinohe, thank you for your reply!

I think they are up to date

 % virtualenv --version
16.7.9 
% pyenv --version
pyenv 1.2.16 

If you mean that it is out of date because of Python version 3.7.5, that is the version of the environment I created, as the installation guide requires a python v3.7.x.
From https://github.com/MTG/sms-tools:

How to use
In order to use these tools you have to install python (recommended 3.7.x) and the following modules: ipython, numpy, matplotlib, scipy, and cython.

Yes, well I use 3.8 and it's working here..

Offline

#5 2020-01-30 12:48:25

tuliochiodi
Member
From: Brazil
Registered: 2020-01-29
Posts: 6

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

qinohe wrote:

You also need to install python-pmw [Community] to use the  Tkinter module.

I tried installing via pacman and via pip, none worked sad


qinohe wrote:

Yes, well I use 3.8 and it's working here..

I tried to create another environment with python 3.8, it also didn't work.

I have no idea where I should go to find out the cause of the problem hmm

My virtual environment? My python pre installed? Problem installing tk / tcl? Any problem with Tkinter? hmm


smile

Offline

#6 2020-01-30 14:12:24

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

tuliochiodi wrote:

I tried installing via pacman and via pip, none worked sad

I installed 'python-pmw tk tcl' with pacman.
Do you get any messages if you try to install them with pacman ?

I tried to create another environment with python 3.8, it also didn't work.

I have no idea where I should go to find out the cause of the problem hmm

My virtual environment? My python pre installed? Problem installing tk / tcl? Any problem with Tkinter? hmm

Well I'm a python newbie myself, but I always update pip in venv to latest and greatest.
I do nothing in my native env., always venv, besides installing python packages with pacman..

As far as I can see I have no problems Tkinter and when I compiled 'compileModule.py' (sms-tools) I don't see the error you see.
That is, I had the error but then I installed python-pwm and all was good.
I have no real good idea with could be wrong with your env., do exactly as your told in the wiki(venv) and then follow sms-tools exactly and it should work.

Also, welcome to Arch wink

Offline

#7 2020-01-30 14:35:32

tuliochiodi
Member
From: Brazil
Registered: 2020-01-29
Posts: 6

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

Well I'm a python newbie myself, but I always update pip in venv to latest and greatest.
I do nothing in my native env., always venv, besides installing python packages with pacman..

As far as I can see I have no problems Tkinter and when I compiled 'compileModule.py' (sms-tools) I don't see the error you see.
That is, I had the error but then I installed python-pwm and all was good.
I have no real good idea with could be wrong with your env., do exactly as your told in the wiki(venv) and then follow sms-tools exactly and it should work.

Also, welcome to Arch

I get no error compiling 'compileModule.py'. My error is importing Tkinter on python.
You had the same error as me before installing python-pwm?

Thank you qinohe big_smile

I'll keep trying, if I get to any solution I'll post here big_smile


smile

Offline

#8 2020-01-30 14:54:28

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

I get no error compiling 'compileModule.py'.

You're right, I had the problem running 'python models_GUI.py '

You had the same error as me before installing python-pwm?

Yes, after installing it(pacman) I could run 'python models_GUI.py' and a GUI was opened.

Offline

#9 2020-01-30 22:51:40

tuliochiodi
Member
From: Brazil
Registered: 2020-01-29
Posts: 6

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

Okay, I'll post here if there is any evolution.
Thank you smile


smile

Offline

#10 2020-01-31 00:27:34

tuliochiodi
Member
From: Brazil
Registered: 2020-01-29
Posts: 6

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

I uninstalled my pyenv, pyenv-virtualenv, virtualenv and virtualenvwrapper.
After that I installed conda, created a new env and it's working.

Thank you for your time qinohe big_smile


smile

Offline

#11 2024-01-30 11:19:13

j1wu
Member
Registered: 2024-01-30
Posts: 1

Re: Python/Tkinter : ModuleNotFoundError: No module named '_tkinter'

For reference:

After installing Tk on the computer, it is necessary to rerun `pyenv install <version>`.

Offline

Board footer

Powered by FluxBB