How to set the default encoding to UTF-8 in Python
===

I' runing a recent Linux system where all my locales are UTF-8:

    LANG=de_DE.UTF-8
    LANGUAGE=
    LC_CTYPE="de_DE.UTF-8"
    LC_NUMERIC="de_DE.UTF-8"
    LC_TIME="de_DE.UTF-8"
    ...
    LC_IDENTIFICATION="de_DE.UTF-8"
    LC_ALL=

**So I want to set the default locale to UTF-8 in Python too.**

Right now Python uses UTF-8 for the FS encoding but sticks to ASCII for the default encoding :(

    >>> import sys
    >>> sys.getdefaultencoding()
    'ascii'
    >>> sys.getfilesystemencoding()
    'UTF-8'

BTW: This mismatch is especially troubling eg. it raises a `UnicodeError` in **virtualenv** if I use a path with non ASCII chars.

I thought the best (clean) way to do this was setting the ``PYTHONIOENCODING`` environment variable. But it seems that Python ignores it. At leat on my system I keep getting `ascii` as default encoding, even after setting the envvar.

    # tried this in ~/.bashrc and ~/.profile (also sourced them)
    # and on the commandline before running python
    export PYTHONIOENCODING=UTF-8

If I do the following at the start of a script, it works though:

    >>> import sys
    >>> reload(sys)  # to enable `setdefaultencoding` again
    <module 'sys' (built-in)>
    >>> sys.setdefaultencoding("UTF-8")
    >>> sys.getdefaultencoding()
    'UTF-8'
    
But that approach seems unclean and also doesn't prevent the errors I get in *virtualenv* and similar problems. So, what's a good way to accomplish this?