Unfortunately not even editing .profile works for me; I can see that the 
variables are set but Python's behavior is the same. While working on it I 
did notice that sys.getfilesystemencoding() returns "utf-8", with or 
without the new lines in .profile, so the problem may be Python-specific.

I found another Stack Overflow question 
<http://stackoverflow.com/a/18292358/2829764> that says

> 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.  

If this is correct then what I really want is to change the Spyder console 
to use ascii rather than changing Python run in other contexts to use utf-8.

I've just checked and seen that when I run sys.getdefaultencoding() in 
Spyder's internal console I get 'ascii'. So I guess I can just remove the 
code to set the default encoding to utf-8 from sitecustomize.py without 
breaking the environment that Spyder itself runs in. Is that correct?

I wonder why Spyder defaults to utf-8 in the first place, if it's not what 
the program uses internally.

On Wednesday, June 18, 2014 5:24:50 PM UTC-4, Adrian Klaver wrote:
>
> On 06/16/2014 09:30 PM, Evan Carter wrote: 
> > You are right that Spyder is messing with the encoding in its 
> > sitecustomize.py 
> > <
> https://code.google.com/p/spyderlib/source/browse/spyderlib/widgets/externalshell/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"|. 
> > 
>
> Some Googling seems to indicate this SO question has the answer: 
>
>
> http://stackoverflow.com/questions/7165108/in-osx-lion-lang-is-not-set-to-utf8-how-fix/8161863#8161863
>  
>
> Try adding or editing the ~/.profile file for it to correctly export 
> your locale settings upon initiating a new session. 
>
> export LC_ALL=en_US.UTF-8 
> export LANG=en_US.UTF-8 
>
> These two lines added to the file should suffice to set the locale 
> [replace en_US for your desired locale, and check beforehand that it is 
> indeed installed on your system (locale -a)]. 
>
> After that, you can start a new session and check using locale: 
>
>
> If that does not work, I would say this is question for some OS X 
> experts, of which I am not. 
>
>
>
> -- 
> Adrian Klaver 
> [email protected] <javascript:> 
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.

Reply via email to