Homebrew Vim doesn't start with Python 3.8 error Note

TL;DR:

Setting the LC_CTYPE environment variable to ja_JP.UTF-8 fixed it.

Investigation

When I start vim, it crashes with the following error.

% vim
Fatal Python error: config_get_locale_encoding: failed to get the locale encoding: nl_langinfo(CODESET) failed
Python runtime state: preinitialized

A search in the error message found a thread in the Python bug tracker. https://bugs.python.org/issue39397

A mistake in setting the locale has been pointed out. You are also advised to remove the LC_CTYPE environment variable. The reporter himself seems to have solved the problem by removing the LANG environment variable.

Check your environment.

% locale
LANG="ja_JP.UTF-8"
LC_COLLATE="ja_JP.UTF-8"
LC_CTYPE="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_ALL=

% echo $LANG
ja_JP.UTF-8

% env | grep '^LC_ALL=' #undefined
% env | grep '^LC_CTYPE=' #undefined

The LANG environment variable is set. The LC_CTYPE environment variable is not set, so the locale command sets the locale setting LC_CTYPE to ja_JP.UTF-8.

I don't want to change the setting of the LANG environment variable in my environment, so look for another solution.

Here, I investigated the meaning of nl_langinfo (CODESET), which seems to be the location where the error occurred. https://linuxjm.osdn.jp/html/LDP_man-pages/man3/nl_langinfo.3.html

The nl_langinfo () function provides a more flexible way to access locale information than localeconv (3). You can query individual or additional elements of the locale category. … CODESET (LC_CTYPE) Returns a string indicating the character encoding name used in the selected locale.

nl_langinfo (CODESET) seems to be related to the locale setting LC_CTYPE. Its value should be equal to the value of the LC_CTYPE environment variable (for the LC_ALL environment variable if undefined, or for the LANG environment variable if it is also undefined). In my environment, it should be ja_JP.UTF-8, which is the same as the value of the LANG environment variable, but it seems that the acquisition is not successful.

Try setting the LC_CTYPE environment variable to ja_JP.UTF-8.

% export LC_CTYPE=ja_JP.UTF-8
% vim

Vim should now start without any problems.

environment

Vim

% brew info vim
vim: stable 8.2.0654 (bottled), HEAD
Vi 'workalike' with many additional features
https://www.vim.org/
Conflicts with:
  ex-vi (because vim and ex-vi both install bin/ex and bin/view)
  macvim (because vim and macvim both install vi* binaries)
/usr/local/Cellar/vim/8.2.0654 (1,888 files, 32.6MB) *
  Poured from bottle on 2020-05-02 at 10:16:41
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/vim.rb
==> Dependencies
Required: gettext ✔, lua ✔, perl ✔, [email protected] ✔, ruby ✔

% grep '^Plug ' .vimrc
Plug 'Shougo/deoplete.nvim' " |deoplete_nvim|
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'

The deoplete.nvim plugin depends on Python 3. This plugin seems to crash trying to load Python 3.

Python

% brew info [email protected]
[email protected]: stable 3.8.2 (bottled) [keg-only]
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/[email protected]/3.8.2 (4,196 files, 64MB)
  Poured from bottle on 2020-03-16 at 14:48:28
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/[email protected]

macOS

% sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.3
BuildVersion:   19D76

Recommended Posts

Homebrew Vim doesn't start with Python 3.8 error Note
[Note] Anaconda & VScode has trouble with python import error
Start numerical calculation in Python (with Homebrew and pip)
[Note] Operate MongoDB with Python
Format json with Vim (with python)
Setup modern Python environment with Homebrew
(Note) Be careful with python argparse
[Note] Hello world output with python
Manage each Python version with Homebrew
When matplotlib doesn't work with python2.7
Build Vim with MinGW. (+ lua, + python)
Error and solution when installing python3 with homebrew on mac (catalina 10.15)
[Note] Get data from PostgreSQL with Python
Note when creating an environment with python
Start python
Note: Python
[Personal note] Web page scraping with python3
Trying to handle SQLite3 with Python [Note]
What to do if the server doesn't start with python manage.py runserver
Python note
Publish your own Python library with Homebrew
Homebrew error
Error when installing a module with Python pip
[Note] Export the html of the site with python.
Let's write FizzBuzz with an error: Python Version
pyenv doesn't work with tcl-tk installed by homebrew.
Start a simple Python web server with Docker
[Note] Create a one-line timezone class with python
I wanted to install Python 3.4.3 with Homebrew + pyenv
Allow vim quickfix to jump to Python error messages
Note for formatting numbers with python format function
Install vim7.3 (+ python2.4) from source (compatible with Gundo.vim)
Install Python 3 on MacOS Catalina (with Homebrew only)
Python script to get note information with REAPER
Python study note_002
Note: Python Decorator
FizzBuzz with Python3
Python programming note
Scraping with Python
[Python] Learning Note 1
Scraping with Python
Python with Go
Python study note_004
Twilio with Python
Integrate with Python
Start using Python
Python quick start
Play with 2016-Python
AES256 with python
Tested with Python
[Python] Start studying
python starts with ()
with syntax (Python)
Python study note_003
Vim with Atom
Bingo with python
Zundokokiyoshi with python
[Note] openCV + python
Python beginner's note
Excel with Python
Microcomputer with Python