What is wxPython doing to the locale to makes pandas crash?

Robin,

This won’t work in linux:

        lang, enc = locale.getdefaultlocale()
        self._initial_locale = wx.Locale(lang, lang[:2], lang)
        locale.setlocale(locale.LC_ALL, lang)

locale.setlocale would raise

locale.Error: unsupported locale setting

What would work is:

locale.setlocale(locale.LC_ALL, (lang, enc))

Of course, this does not work in windows, so you might want to try one, and if a locale.Error is raised try the other.

Is there a bug report for this issue somewhere?

it works in my code following this :

In main page I have :
(self.locale = wx.Locale(wx.LANGUAGE_ENGLISH) for example)

      elif langue == "english" :
          self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
          presLan = gettext.translation("en", "./locale", languages=['en'])
          self.langage_utilisateur = "english"
          langue_par_defaut = "en_GB"
      elif langue == "french" :
          self.locale = wx.Locale(wx.LANGUAGE_FRENCH)
          presLan = gettext.translation("fr", "./locale", languages=['fr'])
          self.langage_utilisateur = "francais"
          langue_par_defaut = "fr_FR"
      elif langue == "spanish" :
          self.locale = wx.Locale(wx.LANGUAGE_SPANISH)
          presLan  = gettext.translation("es", "./locale", languages=['es'])
          self.langage_utilisateur = "espanol"
          langue_par_defaut = "es_ES"
presLan.install()

and before a call who used to crash in windows (strptime for example) :
(locale.setlocale(locale.LC_ALL, ‘en’) for example)

            if ( parent.parent.systeme_version == "WINDOWS" ) :
                if ( parent.parent.langage_utilisateur == "english" ) :
                    locale.setlocale(locale.LC_ALL, 'en')
                if ( parent.parent.langage_utilisateur == "francais" ) :
                    locale.setlocale(locale.LC_ALL, 'fr')
                if ( parent.parent.langage_utilisateur == "espanol" ) :
                    locale.setlocale(locale.LC_ALL, 'es')
                    
            date_formate_en_float = date2num(datetime.datetime.strptime(date_heure_formatee, '%Y%m%d%H%M'))

Hope it will be usefull, not clean method for sure …

    class MyApp(wx.App):
        def InitLocale(self):
            self.ResetLocale()

This works for me!

OS Windows 10, wxpython 4.1.0 and python 3.8.3

Thanks you!

1 Like

Install wxPython version 4.0.7 and it works great

1 Like

Yep, this works for me as well.

I just pip installed the wxPython 4.1 and I still see the bug. I’m using python 3.8.6 on windows 10 (update 2004). I was able to get around the problem by using:
import locale
locale.setlocale(locale.LC_ALL, ‘en’)

But I’m that is not the best solution. Also adding the self.ResteLocale() did not work?
Johnf

After lot of code updates, just reverting back to 4.0.7 worked.

This seems the best & clean option, until issue fixed in 4.1.x

Windows 10, python 3.7.9, pandas 1.1.4, wxPython 4.1.0

pip install -U wxPython==4.1.1

This works for me!

I had a very similar locale problem, although not (apparently) due to a conflict with pandas. Of all the proffered solutions (and thanks very much to everyone), the only one that fixed it for me was downgrading to wxPython-4.0.7.post2.

Quite happy to blame Bill Gates for this one, regardless of whether it’s his fault.

Windows 10, Python 3.8.

Out of interest, the problem is NOT present for me with wxPython 4.1.0.