Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxpython 3.0 breaks older apps? (locale error)

I had an app that was working properly with old verions of wxpython

Now with wxpython 3.0, when trying to run the app, I get the following error

  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_controls.py", line 6523, in __init__
    _controls_.DatePickerCtrl_swiginit(self,_controls_.new_DatePickerCtrl(*args, **kwargs))
wx._core.PyAssertionError: C++ assertion "strcmp(setlocale(LC_ALL, NULL), "C") == 0" failed at ..\..\src\common\intl.cpp(1449) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a mismatch between C/C++ and Windows locale.
Things are going to break, please only change locale by creating wxLocale objects to avoid this!

the error comes from this line

File "C:\Users\hadi\Dropbox\Projects\Python\dialysis\profile.py", line 159, in __init__
    style=wx.DP_DROPDOWN)

Help is much appreciated

like image 385
Hadi Avatar asked Jan 29 '14 23:01

Hadi


2 Answers

I know it's been a while since this question was asked, but I just had the same issue and thought I'd add my solution in case someone else finds this thread. Basically what's happening is that the locale of your script is somehow conflicting with the locale of the machine, although I'm not sure how or why. Maybe someone else with more specific knowledge on this can fill that in. Try manually setting the locale using the wxPython object wx.Locale:

locale = wx.Locale(wx.LANGUAGE_ENGLISH)

However, make sure that you assign the output to a non-local variable. As soon as the variable goes out of scope, the Locale object is destructed. So if it's in a class:

class MyApp(wx.App): ... def OnInit(self): self.locale = wx.Locale(wx.LANGUAGE_ENGLISH) ...

like image 77
dpwilson Avatar answered Oct 20 '22 16:10

dpwilson


I've just faced the same kind of issue. It seems we need to set the locale before using the wx.App :

import locale
locale.setlocale(locale.LC_ALL, 'C')

Two links helped me to solve this issue :

  • Solution found in PHP : https://github.com/wxphp/wxphp/issues/108
  • How to do the same in Python : How to set Python default locale on Windows?

My original error message :

..\..\src\common\intl.cpp(1449): assert "strcmp( setlocale(LC_ALL, NULL), "C")==0" failed in wxLocale::GetInfo() ...
like image 5
SSIsyphe Avatar answered Oct 20 '22 17:10

SSIsyphe