Python 3 UnicodeEncodeError: 'ascii' codec can't encode characters
<p>I've just started to learn Python but I already ran into troubles.<br />
I have a simple script with just one command:</p>
<pre><code>#!/usr/bin/env python3
print(&quot;Příliš žluťoučký kůň úpěl ďábelské ódy.&quot;) # Text in Czech 
</code></pre>
<p>When I try to run this script:</p>
<pre><code>python3 hello.py 
</code></pre>
<p>I get this message:</p>
<pre><code>Traceback (most recent call last):
  File &quot;hello.py&quot;, line 2, in &lt;module&gt;
    print(&quot;P\u0159\xedli\u0161 \u017elu\u0165ou\u010dk\xfd k\u016fn \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy.&quot;)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128)
</code></pre>
<p>I am using Kubuntu 16.04 and Python 3.5.2.
When I tried this: <code>export PYTHONIOENCODING=utf-8</code> It worked but only temporarily. Next time I opened bash I got the same error.</p>
<p>According to <a href="https://docs.python.org/3/howto/unicode.html#the-string-type" rel="nofollow noreferrer">https://docs.python.org/3/howto/unicode.html#the-string-type</a>
<strong>the default encoding for Python source code is UTF-8.</strong><br />
So I have the source file saved id UTF-8, Konsole is set to UTF-8 but I still get the error!<br />
Even if I add</p>
<pre><code># -*- coding: utf-8 -*-
</code></pre>
<p>to the beginning it does nothing.</p>
<p>Another weird thing: when I run it using only python, not python3, it works. How is it possible to work in Python 2.7.12 and not in 3.5.2?</p>
<p>Any ideas for solving this permanently? Thank you.</p>