Generating a PNG with matplotlib when DISPLAY is undefined

前端 未结 12 1469
感动是毒
感动是毒 2020-11-22 02:51

I am trying to use networkx with Python. When I run this program it get this error. Is there anything missing?

#!/usr/bin/env python

import networkx as nx
i         


        
12条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 02:58

    I found this snippet to work well when switching between X and no-X environments.

    import os
    import matplotlib as mpl
    if os.environ.get('DISPLAY','') == '':
        print('no display found. Using non-interactive Agg backend')
        mpl.use('Agg')
    import matplotlib.pyplot as plt
    

提交回复
热议问题