title: UnicodeEncodeError in python3
body: <p>Some of my application's libraries are depending on being able to print UTF-8 characters to stdout and stderr. Therefore this must not fail:</p>
  
  <pre><code>print('\u2122')
  </code></pre>
  
  <p>On my local machine it works, but on my remote server it raises <code>UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in position 0: ordinal not in range(128)</code></p>
  
  <p>I tried <code>$ PYTHONIOENCODING=utf8</code> with no apparent effect.</p>
  
  <pre><code>sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
  </code></pre>
  
  <p>works for a while, then stalls and finally fails with <code>ValueError: underlying buffer has been detached</code></p>
  
  <p><code>sys.getdefaultencoding()</code> returns <code>'utf-8'</code>, and <code>sys.stdout.encoding</code> returns <code>'ANSI_X3.4-1968'</code></p>
  
  <p>What can I do? I don't want to edit third-party libraries.</p>