title: How to fix Python encoding in terminal
body: <p>How do you set the default encoding Python uses with <code>sys.stdout</code> when run from a terminal program like Gnome-Terminal?</p>
  
  <p>If I execute a Python script inside Gnome-Terminal, I get the notorious "UnicodeEncodeError: 'ascii' codec can't encode character" error if the script tries to print unicode characters. However, even though Gnome-Terminal's encoding is set to "UTF-8", if I print <code>sys.stdout.encoding</code> it shows "ANSI_X3.4-1968".</p>
  
  <p>Minimal code to reproduce the error is:</p>
  
  <pre><code>python -c 'import sys; print sys.stdout.encoding; print u"\u0411\n"'
  </code></pre>
  
  <p>Why isn't Python using the terminal's encoding of utf-8?</p>
  
  <p>Note, I'm <em>not</em> asking how to convert my string to ASCII.</p>