My Matplotlib backend keeps reverting to TkAgg
. This is a problem because in the Windows Subsystem for Linux (WSL), you can't do GUI stuff, and so I get the error
TclError: no display name and no $DISPLAY environment variable
I've tried adding a matplotlibrc
file to /home/<user>/.config/matplotlib
(in the Windows filesystem, this is C:\\Users\\<user>\\AppData\\Local\\lxss\\home\\<user>\\.config\\matplotlib
).
My matplotlibrc
looks like this
backend : Agg
However, if I do this
$ cd /home/<user>/.config/matplotlib
$ ls -A
nothing shows up.
When I try
$ python
>>> import matplotlib
>>> matplotlib.get_backend()
'TkAgg'
so clearly it's not setting the backend to Agg
. Why not?
Update:
I've figured out that putting backend : Agg
in C:\\Users\\<user>\\AppData\\Local\\lxss\\home\\<user>\\.config\\matplotlib\\matplotlibrc
changes the backend in Windows Python only, leaving Linux Python as TkAgg
. Which is odd, because Windows Python should only be using C:\\Users\\<user>\\AppData\\Local\\Enthought\\Canopy\\User\\Lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc
, right?
I figured it out. I had created the matplotlibrc file using Windows - this is why it didn't show up when I tried $ ls -A
in bash. So I did this instead (after deleting the Windows-created file):
$ cd /home/<user>/.config/matplotlib
$ touch matplotlibrc
$ echo "backend : Agg" > matplotlibrc
( touch matplotlibrc
creates an empty matplotlibrc file)
This did the trick, and my Windows python matplotlib's backend was left as Qt4Agg.
Here it is on one line for copy/paste:
cd /home/<user>/.config/matplotlib; touch matplotlibrc && echo "backend : Agg" > matplotlibrc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.