Search code examples
pythonpython-3.xmacosmacports

python3.8 fails with "Fatal Python error: config_get_locale_encoding"


OK, so somehow I have mangled my python3 installation under macOS Mojave and I'm not sure how. I've used macports for years to keep python up to date but when I installed python38 now I cannot run python3 at all. I always get this:

$ python3.8
Fatal Python error: config_get_locale_encoding: failed to get the locale encoding: nl_langinfo(CODESET) failed
Python runtime state: preinitialized
$

I uninstalled the macports version and reinstalled, same thing. Uninstalled and then installed fresh from python.org, same thing.

python27 runs fine. python37 also runs fine. python38 won't even work if I use $python3.8 -I so it's not some site package weirdness.

Here's the really weird bit: while I cannot run python38 from a shell (any shell, tried from bash , I can launch python38 from the GUI using IDLE.app.

Oddly, on my other machine (my laptop), python38 installed with macports works just fine.

I'm flummoxed and I don't flummox easily. Any ideas?


Solution

  • Try setting LANG with a locale:

    export LANG="en_US.UTF-8"