I am developing a QGIS-plugin and for graphing I want to use matplotlib, like many other QGIS -plugins.
This worked fine under linux, but under windows with QGIS2.4 I am experiencing problems.
I checked and matplotlib seams to be included in the standard windows-install of QGIS. But when people try to install the plugin, they get this report:
The plugin is broken: No Module named tkinter
Turns out even though I'm using pyqt, matplotlib requires tkinter and this seams be to be excluded from the QGIS installation.
Is this a Bug? (should i report it?)
Or is there a way to use matplotlib without loading tkinter?
If I really need tkinter, how can I solve this? As tkinter is a binary python package, i can't include it in my plugin or is there an alternative (pyQWT is also binary, so also not a solution)
I call matplotlib this way:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt
its the experimental version (1.2.0) of this plugin, if you want to try it: http://plugins.qgis.org/plugins/geopunt4Qgis/
-
How did you call matplotlib, with a specific backend (matplotlib backends) ?gene– gene2014年07月09日 16:58:51 +00:00Commented Jul 9, 2014 at 16:58
-
Are they using the stand-alone installer or the OSGeo4W installer?underdark– underdark2014年07月09日 17:15:33 +00:00Commented Jul 9, 2014 at 17:15
-
matplotlib works without problem with the standalone installergene– gene2014年07月09日 17:22:54 +00:00Commented Jul 9, 2014 at 17:22
-
standalone 64bit.warrieka– warrieka2014年07月09日 18:18:50 +00:00Commented Jul 9, 2014 at 18:18
2 Answers 2
OK i found the problem. I made following changes to my code so it doesn't try load tkinter anymore:
I changed:
import matplotlib.pyplot as plt
into:
from matplotlib.figure import Figure
from matplotbib import axes
and change plt.figure() in Figure() etc..
I have found the solution here : https://github.com/gem/oq-irmt-qgis/issues/224. Some plugins blocks access to the tkinter module.
-
very good finding. Following this link I also found the solution to the problem. Thanks a lot for that!fastest– fastest2020年10月24日 20:56:38 +00:00Commented Oct 24, 2020 at 20:56