Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Jan 10 2014, 11:23:15)[GCC 4.0.1 (Apple Inc. build 5493)] on darwinType "help", "copyright", "credits" or "license" for more information.Imported NumPy 1.7.1, SciPy 0.13.0, Matplotlib 1.3.1Type "scientific" for more details.>>> import sys>>> sys.getdefaultencoding()'UTF-8'>>>
Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Jan 10 2014, 11:23:15)[GCC 4.0.1 (Apple Inc. build 5493)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import sys>>> sys.getdefaultencoding()'ascii'
[('SPYDER_ENCODING', 'UTF-8')]
[('LANG', 'en_US.UTF-8')]
You are right that Spyder is messing with the encoding in its sitecustomize.py:
encoding = None
try:
import locale
except ImportError:
pass
else:
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if encoding is None:
encoding = "UTF-8"
try:
sys.setdefaultencoding(encoding)
os.environ['SPYDER_ENCODING'] = encoding
except AttributeError:
# Python 3
pass
If I am so bold as to add encoding = "ascii" then sys.getdefaultencoding()
does indeed give 'ascii' when run from the console, but I don't know
what the consequences will be of messing with the encoding for all of
Spyder. I'd like to change the encoding only for the Python interpreter
in the console, not the Python environment in which Spyder is running.
Unfortunately, adding os.environ['SPYDER_ENCODING'] = 'ascii' doesn't work: the environment variable stays set but sys.getdefaultencoding() still gives "UTF-8".
Unfortunately setting the PYTHONIOENCODING environment variable before I run a Python program from the command line doesn't work either:
$ export PYTHONIOENCODING=UTF-8
$ export | grep PYTHONIOENCODING
declare -x PYTHONIOENCODING="UTF-8"
$ python
Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Jan 10 2014, 11:23:15)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'ascii'The default of Python 2.x is to use ascii. You can change it(can't remember how) but it is not recommended, because it will break libraries that use ascii strings. It is all changed in 3.x. where UTF is the standard.
Hi Evan,
By changing the encoding
in sitecustomize.py,
you would do it only for our Python and IPython consoles and not
for our internals, so it’s perfectly fine if you want to follow
this path.
Cheers,
Carlos
El 18/06/14 22:54, Evan Carter escribió:
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
To post to this group, send email to spyd...@googlegroups.com.