-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Getting "No module named '_tkinter'" error #9017
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
Comments
How did you install mpl? Can you do If you built from source suspect you also need the tk dev packages as well? This is the first report (that I can recall) of using Matplotilb in Windows Subsystem for Linux, you may be a guinea pig 😅 Any notes from you experience with this that could go in the docs would be very appreciated! |
😛 I installed Python 3.6 from source though, omitting the tk packages as I didn't need them. |
Oh, that is easy to fix then import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt If you didn't install tk in your python then you can not use the tk backend. |
Or update your matplotlibrc file to use a different default backend
…On Thu, Aug 10, 2017 at 5:58 PM, Thomas A Caswell ***@***.***> wrote:
Oh, that is easy to fix then
import matplotlib
matplotlib.use('agg')import matplotlib.pyplot as plt
If you didn't install tk in your python then you can not use the tk
backend.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#9017 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-K7c5fXOPUz1laRcc1sOQdNaaik5ks5sW3z2gaJpZM4Oz_H8>
.
|
Closing as this is apparently a python install issue -- but feel free to request a reopen if something else is wrong, or to suggest some change in the docs. |
My 2c: should be reopened for the following reason:
First error is fine, but the second error is not. |
Pyplot sets the backend if it’s lot been set already. The user only need move the import matpltolib and matplotlib.use before the pyplot import. |
That's exactly the problem -- requiring user to do something before they know they need it. |
The issue of pyplot setting the backend is currently being worked on from
multiple angles. This has been a long-standing issue, and it is a very
tricky issue to address. One of the first features that'll likely come out
of it is configuring matplotlib by default to respect a hierarchy of
backend choices, so it can fail-over more gracefully to other backends.
…On Thu, Dec 7, 2017 at 2:25 AM, Dima Tisnek ***@***.***> wrote:
That's exactly the problem -- requiring user to do something before they
know they need it.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9017 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-FOL1l1j6iCIORYW9EX2TO7RAuWYks5s95L6gaJpZM4Oz_H8>
.
|
on minimal install centos7. first yum install -y tkinter tk-devel then in ipython env, import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt # no error, it works
plt.figure(1).show() arisen: /root/venv36/lib/python3.6/site-packages/matplotlib/figure.py:418: UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure I have already Configure X11 forwarding on xshell with the steps of http://www.doxer.org/use-xming-xshell-putty-tightvnc-to-display-linux-gui-on-windows-desktop-x11-forwarding-when-behind-firewall/ but it still not work |
@shenjiefeng with This question would be better handled on the mailing list [email protected] (https://mail.python.org/mailman/listinfo/matplotlib-users you will have to subscribe to post un-moderated). |
importing matplotlib on systems that do not have TkInter installed gives a ModuleNotFoundError (see matplotlib/matplotlib#9017) This commit works around this issue by setting the 'agg' backend for matplotlib.
That is used for me. |
It's a total bummer that matplotlib initializes the backend early, and fails hard. |
3.0.0 will change the backend fallback behaviour. |
The other option is no exceptions and no plots. The cryptic error at least suggests that something is not behaving as expected. |
Thanks @jklymak that's very good to hear! |
in my case on manjaro Linux, installing python-pmw worked it out. |
…without tk or graphic interface. * See here for discussion: matplotlib/matplotlib#9017 (comment) * One can also work around this using by setting a text-based matplotlib backend like so: import matplotlib matplotlib.use('agg') * Error message is like so: File "/home/micha/Documents/git/mmpreprocesspy/venv-testenv/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 5, in <module> import tkinter as Tk ModuleNotFoundError: No module named 'tkinter'
Thank you very much.
…On Sat, Nov 9, 2019 at 6:40 PM MilanP28 ***@***.***> wrote:
sudo apt-get install python3-tk
Then,
import tkinter # all fine
Full source code at icetutor
<https://icetutor.com/question/matplotlib-error-no-module-named-tkinter/>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9017?email_source=notifications&email_token=AHLQRJAU6PJ7KDMAXNMUWKTQS3HGTA5CNFSM4DWP6H6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDUIFWY#issuecomment-552108763>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHLQRJEDNG3WXDFOCOAYU23QS3HGTANCNFSM4DWP6H6A>
.
|
lt;dr? |
I am still getting this on |
@jorijnsmit Can you open a new issue that explains what you are trying to do. w/ 3.2.1 you should get a fallback to |
@jorijnsmit We do not have a hard dependency on an GUI toolkit because there are many uses where you do not need it (batch jobs, use in a notebook, in a webserver etc). The dependency on Tk is further complicated because the bindings are part of the standard library, but some packagers split it out into a separate package. If you think the Matplotliblib package should depend on the python-tk package, please take that up with the maintainers of your packaging tool. |
I know this is an old issue, but I found the most reliable solution to this on macOS, especially in combination with the PyCharm debugger crashing due to matplotlib related tk issues, was to use the backend |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
I just wanted to use matplotlib to draw a line graph and save it to a file, but every time I try to import the pyplot module I get the abovementioned error message.
Actual outcome
Expected outcome
Whatever happens when
import matplotlib.pyplot
succeedsMatplotlib version
I installed matplotlib using pip.
Doing
sudo apt-get install python3-tk
, as recommended by someone on Stack Overflow, didn't help.The text was updated successfully, but these errors were encountered: