Issue
I am having problems with matplotlib.pyplot.show()
function. I am using PyCharm on Linux, and i have a VirtualEnv. When i execute the file x.py in the built terminal in PyCharm (using venv) like this
$ python x.py
everything works fine, the function plt.show()
renders and shows the plotted graph well. i did add print(matplotlib.get_backend())
to see which backend was used by default and the result was GTK3Agg.
The problem starts when i use the option Run and not the terminal. Then i get an error message
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. plt.show()
Anyways, i searched online and according to this and other links, i had to add backend: GTK3Agg
in .config/matplotlib/matplotlibrc . The file did not exist so i created it myself. Now when i run again, i get the following error messages:
raise ImportError('backend Gtk3Agg requires cairo') from e ImportError: backend Gtk3Agg requires cairo
How can i fix this ?
Solution
I managed to solve my problem, thanks to @ImportanceOfBeingErnest pointing out that i had two environments, one where GTK and dependencies are installed, and one, which is used by PyCharm, where those are missing.
I had to go to Settings > Project interpreter
and install matplotlib, pycairo and PyGObject.
Also neccessary to install pycairo and PyGObject were these packages, which i had to install from the terminal:
sudo dnf install cairo-devel (or libcairo2 in ubuntu)
sudo dnf install python3-devel
sudo dnf install gobject-introspection-devel
sudo dnf install cairo-gobject-devel
Now i can use GTK3Agg as my backend.
Answered By - user2719475
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.