Generating a PNG with matplotlib when DISPLAY is undefined

前端 未结 12 1259
感动是毒
感动是毒 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:59

    I will just repeat what @Ivo Bosticky said which can be overlooked. Put these lines at the VERY start of the py file.

    import matplotlib
    matplotlib.use('Agg') 
    

    Or one would get error

    */usr/lib/pymodules/python2.7/matplotlib/__init__.py:923: UserWarning:  This call to   matplotlib.use() has no effect
    because the the backend has already been chosen;
    matplotlib.use() must be called *before* pylab, matplotlib.pyplot,*
    

    This will resolve all Display issue

提交回复
热议问题