title: How to check DISPLAY=:0 exist from python?
body: <p>Command:</p>
  
  <p><code>ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u</code></p>
  
  <p>Output:</p>
  
  <p><code>DISPLAY=:0</code></p>
  
  <p>How to check <code>DISPLAY=:0</code> exist from python?</p>
  
  <p>While <code>DISPLAY=:0</code> exist, <code>import os; print(os.environ['DISPLAY'])</code> not.</p>
  
  <pre><code>python -c "import os; print(os.environ['DISPLAY'])"
  Traceback (most recent call last):
    File "&lt;string&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python3.6/os.py", line 669, in __getitem__
      raise KeyError(key) from None
  KeyError: 'DISPLAY'
  </code></pre>
  
  <p>For some reason this outputs empty string:</p>
  
  <pre><code>import subprocess
  subprocess.getoutput('ps e | grep -Po " DISPLAY=[\\.0-9A-Za-z:]* " | sort -u')
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>''
  </code></pre>