Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: No module named _tkinter when i have it installed tkinter using pip3 install tk #22583

Closed
ayush-india opened this issue Mar 2, 2022 · 1 comment

Comments

@ayush-india
Copy link

ayush-india commented Mar 2, 2022

Bug summary

When i try to run a piece of code which will just basicilly animate the chaos equation(i know it sounds a lot mathhy ) it gives me this error

Traceback (most recent call last):
File "/home/ayu/b.py", line 4, in
import matplotlib.pyplot as plt
File "/usr/local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 2230, in
switch_backend(rcParams["backend"])
File "/usr/local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 267, in switch_backend
class backend_mod(matplotlib.backend_bases._Backend):
File "/usr/local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 268, in backend_mod
locals().update(vars(importlib.import_module(backend_name)))
File "/usr/local/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.10/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in
from . import _backend_tk
File "/usr/local/lib/python3.10/site-packages/matplotlib/backends/_backend_tk.py", line 7, in
import tkinter as tk
File "/usr/local/lib/python3.10/tkinter/init.py", line 37, in
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
from mpl_toolkits.mplot3d import Axes3D

rho = 28.0
sigma = 10.0
beta = 8.0 / 3.0

def f(state, t):
    x, y, z = state  # Unpack the state vector
    return sigma * (y - x), x * (rho - z) - y, x * y - beta * z  # Derivatives

state0 = [1.0, 1.0, 1.0]
t = np.arange(0.0, 40.0, 0.01)

states = odeint(f, state0, t)

fig = plt.figure()
ax = fig.gca(projection="3d")
ax.plot(states[:, 0], states[:, 1], states[:, 2])
plt.draw()
plt.show()

Actual outcome

it gives me this error

Traceback (most recent call last):
File "/home/ayu/b.py", line 4, in
import matplotlib.pyplot as plt
File "/usr/local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 2230, in
switch_backend(rcParams["backend"])
File "/usr/local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 267, in switch_backend
class backend_mod(matplotlib.backend_bases._Backend):
File "/usr/local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 268, in backend_mod
locals().update(vars(importlib.import_module(backend_name)))
File "/usr/local/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.10/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in
from . import _backend_tk
File "/usr/local/lib/python3.10/site-packages/matplotlib/backends/_backend_tk.py", line 7, in
import tkinter as tk
File "/usr/local/lib/python3.10/tkinter/init.py", line 37, in
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

Expected outcome

it should animate the chaos equation

https://upload.wikimedia.org/wikipedia/commons/1/13/A_Trajectory_Through_Phase_Space_in_a_Lorenz_Attractor.gif

Additional information

No response

Operating system

lubuntu20.04 (a fork of ubuntu20.04)

Matplotlib Version

3.5.1

Matplotlib Backend

agg

Python version

3.10.0

Jupyter version

i do not have install jupyter notebook

Installation

pip

@oscargus
Copy link
Contributor

oscargus commented Mar 2, 2022

It says here: # If this fails your Python may not be configured for Tk. So this is not a Matplotlib issue. You should be able to trigger it just by doing

import tkinter

in a Python prompt, which rules out Matplotlib.

See e.g. https://stackoverflow.com/questions/59987762/python-tkinter-modulenotfounderror-no-module-named-tkinter for further advice, but it may be that you need to install python-tk though lubuntu as sudo apt-get install python3-tk.

Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants