Automatic detection of display availability with matplotlib

后端 未结 7 1652
悲&欢浪女
悲&欢浪女 2020-12-15 06:26

I\'m generating matplotlib figures in a script which I run alternatively with or without a graphical display. I\'d like the script to adjust automatically: with display, it

7条回答
  •  轮回少年
    2020-12-15 07:12

    import os
    have_display = bool(os.environ.get('DISPLAY', None))
    

    have_display is False if DISPLAY is not in the environment or is an empty string. otherwise, it's True

提交回复
热议问题