title: Opening an UTF-8 encoded file by a Python 3.6 script running in PyCharm 2016.3.2
body: <p>I have a quite odd problem with PyCharm and a Python app that I am working on. </p>
  
  <ul>
  <li>Pycharm is PyCharm Community Edition 2016.3.2</li>
  <li>The project interpreter is: 3.6.0</li>
  <li>OS is MacOS Sierra</li>
  </ul>
  
  <p>As I am have been googling for a solution for some time and no proposed idea helps I want to ask here.</p>
  
  <p>I want to open an UTF-8 encoded file using the following code:</p>
  
  <pre><code>#!/usr/bin/env python3    
  
  import os, platform
  
  def read(file):
      f = open(file, "r")
      content = f.read()
      f.close()
      return content
  
  print(platform.python_version())
  print(os.environ["PYTHONIOENCODING"])
  
  content = read("testfile")
  print(content)
  </code></pre>
  
  <p>The code crashes when run in PyCharm. The output is </p>
  
  <pre><code>3.6.0
  UTF-8
  Traceback (most recent call last):
    File "/Users/xxx/Documents/Scripts/pycharmutf8/file.py", line 14, in &lt;module&gt;
      content = read("testfile")
    File "/Users/xxx/Documents/Scripts/pycharmutf8/file.py", line 7, in read
      content = f.read()
    File "/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
      return codecs.ascii_decode(input, self.errors)[0]
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)
  </code></pre>
  
  <p>When I run the identical code from command line, it works just fine:</p>
  
  <pre><code>./file.py 
  3.6.0
  utf-8:surrogateescape
  I am a file with evil unicode characters: äöü
  </code></pre>
  
  <p>I have found out that in comparable situations people are advised to set the environment variable <code>PYTHONIOENCODING</code> to <code>utf-8:surrogateescape</code> that I did (as you can see in above output) system-wide</p>
  
  <pre><code>export PYTHONIOENCODING=utf-8:surrogateescape
  </code></pre>
  
  <p>but also in PyCharm itself (Settings -> Build -> Console -> Python Console -> Environment variables).</p>
  
  <p>This does not have any effect. Do you have further suggestions?</p>