On 18 Feb, 2013, at 21:22, Pierre Ratinaud <ratin...@univ-tlse2.fr> wrote:

> Hi,
>> I'm not sure. What kind of encoding error occurs? The exact error message 
>> might give a hint as to what's going on here.
> The only message I had was in Console. The software I'm using with Popen (R) 
> is complaining (in french) about encoding in my script.
> 
> My tests and googling leave me to the conclusion that it is an environment 
> problem :
> in the working cases, locale.getpreferredencoding() give me fr_FR.UTF-8 but 
> when double-clicking on the app it gives me us_US.ASCII.
> In R, Sys.getlocale() give me :
> "LC_CTYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=C"
> and just
> "C" when double-clicking.
> This happens with or without --emulate-shell-environment
> So environment (locale) is not set when double-clicking on app. Also, setting 
> locale in my R script resolves the problem, but it's not a solution in my 
> case (a lot of R script to change). I am about to test setting locale in 
> python (with the env option of Popen), but I need to reboot in OS X : )
> Thanks for your help.

The startup binary voor pyapp forces LC_CTYPE to en_US.UTF-8 during the call to 
Py_Initialize, and resets it to whatever it was before afterwards. This is 
primairly done to ensure a sane I/O encoding when using Python 3 (that is, for 
the '.UTF-8' bit).  

I can only test with 10.6 in a virtual machine, I should have some time later 
this week to do so (in particular to check what locale related environment 
variables are set automaticly there and to find why --emulate-shell-environmet 
doesn't pick those up).

You can force the right settings by setting them yourself in your python script 
(os.environ['LC_CTYPE'] = 'fr_FR.UTF-8', etc., etc., before calling 
subprocess.Popen). That's suboptimal, but should at least give you a working 
program without changing all R scripts.

Ronald

> Regards
> Pierre
> 
> 
> 
> Le 18/02/2013 13:28, Ronald Oussoren a écrit :
>> On 17 Feb, 2013, at 10:02, Pierre Ratinaud <ratin...@univ-tlse2.fr> wrote:
>> 
>>> Hi all,
>>> I have create a .app with py2app for a wxpython application. The resulting 
>>> app does not work as expected if I double click on it (it works but 
>>> somewhere in the process, an encoding problem appear from another program 
>>> called with os.popen). This problem does not occur if I launch my app 
>>> directly with python, it does not occur if I launch the app by double-clic 
>>> on myapp inside the .app and it does not occur if I open the .app from a 
>>> terminal with the "open" command.
>>> This is happening with python 2.7.2, wxpython2.9, py2app 0.7.3 under Mac OS 
>>> X 10.6.8.
>>> What am I missing ?
>> I'm not sure. What kind of encoding error occurs? The exact error message 
>> might give a hint as to what's going on here.
>> 
>> What's really strange is that double-clicking the app does not have the same 
>> behavior as calling the open command, I'd expect that those would be behave 
>> the same.
>> 
>> Do you have a shell environment variable in your shell's profile 
>> (.profile/.bash_profile/...) that is needed by the other program? Those 
>> definitions aren't seen by applications launched through the Finger because 
>> the Finder doesn't read the shell's profile.   You could try to use " python 
>> setup.py py2app --emulate-shell-environment" to build the app bundle, that 
>> activates a hack that does try to read the shell environment.
>> 
>> Ronald
>>> thanks
>>> Pierre
>>> 
>>> _______________________________________________
>>> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
>>> http://mail.python.org/mailman/listinfo/pythonmac-sig
>>> unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
>> 
>> 
>> -- 
>> Pierre Ratinaud
>> Maître de conférences
>> Département des Sciences de l'Education et de la Formation
>> Laboratoire LERASS : http://www.lerass.com/
>> Université de Toulouse II - Le Mirail : http://www.univ-tlse2.fr/
>> tel : 05 61 50 42 28

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

Reply via email to