Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 411
Mike Byrne Avatar asked Mar 06 '20 03:03

Mike Byrne


2 Answers

Try setting LANG with a locale:

export LANG="en_US.UTF-8"
like image 80
wmhiggins Avatar answered Oct 16 '22 16:10

wmhiggins


I had the same problem and fixed it by putting the following variable definition in my ~/.profile:

export LC_CTYPE="en_US.UTF-8"

LC_CTYPE was originally set to "De_DE" and was missing the encoding.

You should choose your language and country and set the value accordingly, e.g. this value for German/Germany:

export LC_CTYPE="de_DE.UTF-8"
like image 30
Michael Dreher Avatar answered Oct 16 '22 16:10

Michael Dreher