Python scripts using Matplotlib fail on a server with the error "no display name and no $DISPLAY environment variable" when generating plots. The issue arises because Matplotlib utilizes the Xwindows backend by default and is incompatible with server environments that lack a graphical user interface (GUI).
To resolve this issue, set Matplotlib to use a non-interactive backend. There are several methods to achieve this:
import matplotlib
matplotlib.use('Agg')
echo "backend: Agg" > ~/.config/matplotlib/matplotlibrc
ssh -X remoteMachine.com
export DISPLAY=mymachine.com:0.0
By implementing one of these solutions, you can configure Matplotlib to operate in a server environment without relying on a GUI.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3