Mike Byrne
Mike Byrne

Reputation: 333

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?

Upvotes: 22

Views: 22111

Answers (4)

Bowrna
Bowrna

Reputation: 111

If you are in macOS with default shell as zsh, then you can set export LC_CTYPE="en_US.UTF-8" in your ~/.zprofile and do source ~/.zprofile to reflect on the current terminal screen.

Upvotes: 0

Dmitriy Dokshin
Dmitriy Dokshin

Reputation: 727

There may be another not obvious problem. If you put export LC_CTYPE="en_US.UTF-8" in ~/.profile file, check if there's no ~/.bash_profile in the system. If ~/.bash_profile exists commands in ~/.profile will not be executed.

Upvotes: 0

Michael Dreher
Michael Dreher

Reputation: 1399

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"

Upvotes: 8

wmhiggins
wmhiggins

Reputation: 621

Try setting LANG with a locale:

export LANG="en_US.UTF-8"

Upvotes: 58

Related Questions