Macvim: No module name encodings

Created on 18 Oct 2017  Β·  64Comments  Β·  Source: macvim-dev/macvim

Hey guys :)

I have an issue with LeaderF after updating my macvim:

snapshot-137 works fine,
with snapshot-138 macvim shows:

Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fffa668c340 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.

My .vimrc looks super simple

" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

Plug 'Yggdroot/LeaderF', { 'do': './install.sh' }

" Initialize plugin system
call plug#end()

I published this issue on LeaderF repo as well: https://github.com/Yggdroot/LeaderF/issues/73

Thanks!

Most helpful comment

If your Python is installed with homebrew, try this, it's work for me

if has('python3')
    command! -nargs=1 Py py3 <args>
    set pythonthreedll=/usr/local/Frameworks/Python.framework/Versions/3.6/Python
    set pythonthreehome=/usr/local/Frameworks/Python.framework/Versions/3.6
else
    command! -nargs=1 Py py <args>
    set pythondll=/usr/local/Frameworks/Python.framework/Versions/2.7/Python
    set pythonhome=/usr/local/Frameworks/Python.framework/Versions/2.7
endif

All 64 comments

sounds the same as #554. you need to update Python to 3.6.3.

@splhack does not work :(

➜  ~ python3
Python 3.6.3 (v3.6.3:2c5fed86e0, Oct  3 2017, 00:32:08)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
➜  ~ mvim
➜  ~ Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fff9452a340 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.

➜  ~

UPD Need to install python3 over brew, with official python packages it does not work.

UPD Need to install python3 over brew, with official python packages it does not work.

interesting. the official python binary should work as well as Homebrew one. Could you try to adjust pythonthreedll and pythonthreehome in your .vimrc?

https://github.com/macvim-dev/macvim/blob/dbb801fbab8dc6691952ed32cec58482cfcfe8fa/src/MacVim/vimrc#L27-L36

unfortunately I can not reproduce the error, cause already upgraded my python over brew.

I am seeing crashes with the same error message now:

bqdyn245_127:~ nbecker$ Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fffe49143c0 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.

this is with

mvim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Dec 22 2017 03:30:17)
macOS version
Included patches: 1-1420
Compiled by [email protected]

and with homebrew python3 version 3.6.4_1

the above is snapshot 144. i can avoid the problem by reverting to snapshot 143 @splhack

Also seeing this again with 144

Same error here with MacVim 144 and Homebrew Python3 Version 3.6.4_2

One workaround is to disable python by commenting out _SpaceVim#util#haspyxlib(lib)_.

If your Python is installed with homebrew, try this, it's work for me

if has('python3')
    command! -nargs=1 Py py3 <args>
    set pythonthreedll=/usr/local/Frameworks/Python.framework/Versions/3.6/Python
    set pythonthreehome=/usr/local/Frameworks/Python.framework/Versions/3.6
else
    command! -nargs=1 Py py <args>
    set pythondll=/usr/local/Frameworks/Python.framework/Versions/2.7/Python
    set pythonhome=/usr/local/Frameworks/Python.framework/Versions/2.7
endif

I also get this with Homebrew python 3.6.4_2 and snapshot 144. Reverting to 143 didn't help. Applying @ruchee's suggestion did help.

After setting the python libraries I usually do explicitly call for :py3 or :py to select the version I usually need

@ruchee there's :pyx to call the :py3 or :py after you actually loaded the libraries.

I get the same issue with Homebrew Python 3.6.4 and macvim 8.0.145.

The issue won't happen after remove SpaceVIM. So the issue must be related to SpaceVIM or some of the plugins installed by SpaceVIM.

I have grep -ER 'pythonthreedll|pythonthreehome|pythondll|pythonhome' of all the configurations of SpaceVIM and also all the plugins SpaceVIM installs.

I found nothing but helpful.vim, but removing helpful.vim won't help.

update:

export PYTHONHOME=/usr/local/Frameworks/Python.framework/Versions/Current/ fixed the issue.

@SteamedFish works~

brew install macvim --HEAD resolved this issue for me.

macOS 10.13.3
MacVim 8.0 (patches 1-1591) compiled by Homebrew
Python 3.6.4_4

This happens for me with MacVim snapshot-146-Vim-8.0.1633.

Reverting to snapshot-145-Vim-8.0.1522 makes the problem go away, without any other changes.

OS X version 10.11.6 (15G19009) with Anaconda Python (installed via Miniconda):

$ type -a python
python is /opt/anaconda/bin/python
python is /usr/bin/python
$ python --version
Python 3.6.4 :: Anaconda, Inc.
$ /usr/bin/python --version
Python 2.7.10
$ 

This is reproducible whether or not I first start gvim from within a Python virtual environment with a different Python (Python 2.7.14 :: Anaconda, Inc.). That is:

  1. Quit MacVim altogether
  2. Open a new Terminal window
  3. Run gvim; MacVim opens a new gvim window.
  4. Quit the new gvim window with :q
  5. Open a Python source file using gvim sourcefile.py
  6. Vim aborts with:

    $ Fatal Python error: Py_Initialize: unable to load the file system codec
    ModuleNotFoundError: No module named 'encodings'
    
  7. Quit MacVim altogether

  8. source activate mypy27virtualenv
  9. Run gvim from within the virtual environment
  10. Quit the new gvim window with :q
  11. Open the same Python source file using gvim sourcefile.py
  12. Vim aborts with the same fatal Python error.

Rolling back to snapshot-145-Vim-8.0.1522 makes errors and abort not happen.

Rolling forward to snapshot-146-Vim-8.0.1633 makes the errors and abort happen again.

FWIW I'm encountering this today on macvim 146 after a homebrew update of Python3 to 3.6.5

@aaylward
brew reinstall macvim should work.

The proposed solution unfortunately doesn't fix the problem for me, I still get this error:

~$ gvim
~$ Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fff9bff2340 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.

Trying to install macvim from source gives me the following error and asks me for access to the keychain:

~$ brew reinstall macvim --HEAD
==> Reinstalling macvim 
==> Cloning https://github.com/macvim-dev/macvim.git
Cloning into '/Users/eugencazacu/Library/Caches/Homebrew/macvim--git'...
remote: Counting objects: 3409, done.
remote: Compressing objects: 100% (2884/2884), done.
remote: Total 3409 (delta 530), reused 1563 (delta 425), pack-reused 0
Receiving objects: 100% (3409/3409), 15.24 MiB | 3.27 MiB/s, done.
Resolving deltas: 100% (530/530), done.
==> Checking out branch master
==> ./configure --with-features=huge --enable-multibyte --with-macarchs=x86_64 --enable-perlinterp --enable-rubyinterp --enable-tclinterp -
==> make
Last 15 lines from /Users/eugencazacu/Library/Logs/Homebrew/macvim/02.make:
    export XCODE_DEVELOPER_USR_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin/..
    /Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --strip /tmp/macvim-20180401-4828-1ctlxvt/src/MacVim/build/Release/MacVim.app/Contents/Resources/English.lproj/FindAndReplace.nib --output-format human-readable-text /tmp/macvim-20180401-4828-1ctlxvt/src/MacVim/English.lproj/FindAndReplace.nib

CopyPlistFile build/Release/MacVim.app/Contents/Resources/KeyBinding.plist KeyBinding.plist
    cd /tmp/macvim-20180401-4828-1ctlxvt/src/MacVim
    builtin-copyPlist --outdir /tmp/macvim-20180401-4828-1ctlxvt/src/MacVim/build/Release/MacVim.app/Contents/Resources -- KeyBinding.plist

** BUILD FAILED **


The following build commands failed:
    StripNIB English.lproj/Preferences.nib
(1 failure)
make[1]: *** [macvim] Error 65
make: *** [first] Error 2

READ THIS: https://docs.brew.sh/Troubleshooting

@EugenCazacu This should be another problem discussed in #546 .

Now that worked, thank you very much!

@hu6360567 for some reason I had to do brew reinstall macvim --build-from-source, but now I'm all set. Thanks for your help!

I had to brew reinstall macvim --build-from-source, and then I had to brew reinstall python2, but now it's working for me again. My now working configuration:

> brew info python
python: stable 3.6.5 (bottled), devel 3.7.0b3, HEAD
...
> brew info python2
python@2: stable 2.7.14 (bottled), HEAD 
...
> brew info macvim
macvim: stable 8.0-146 (bottled), HEAD

macOS High Sierra Version 10.13.3

ref: vim/vim#2787

I am getting the same error with snapshot 146. None of the fixes suggested work for me. I can open MacVim, but if I type a single character, including space, it crashes and at the commandline it says:
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Rolling back to snapshot 145_1 makes the problem go away.

This error with python installed with home-brew:

$ mvim
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fffac67c380 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.

It was merged into macvim.
But, 3a21d9c7bb4d58cccd2152e319daa8f8ffa2e664 reverts the change only when --with-python-config-dir is used.
Please don't use the option. As far as I reserched, the option is totally useless.
Setting PATH to python you want to use is the only right way to use custom Python.

I am newly having this error when trying to open a .org file using the vim-orgmode plugin (https://github.com/jceb/vim-orgmode).

Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fff9ff9d380 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.

It is fixed already, but not released yet.

I'm still having hits problem.... It happens when the powerline plugin is installed...

βœ” [brad@bradmac:~] $ brew info macvim python python2
macvim: stable 8.1-151 (bottled), HEAD
GUI for vim, made for macOS
https://github.com/macvim-dev/macvim
Conflicts with:
  vim (because vim and macvim both install vi* binaries)
/usr/local/Cellar/macvim/8.1-151_1 (2,178 files, 34.9MB) *
  Poured from bottle on 2018-11-28 at 18:22:00
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/macvim.rb
==> Dependencies
Required: cscope βœ”, lua βœ”, luajit βœ”, python βœ”
==> Requirements
Build: xcode βœ”
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 15,136 (30 days), 39,398 (90 days), 270,705 (365 days)
install_on_request: 13,909 (30 days), 35,742 (90 days), 220,525 (365 days)
build_error: 0 (30 days)

python: stable 3.7.1 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/2.7.12_1 (6,289 files, 85.5MB)
  Built from source on 2016-10-08 at 09:31:47
/usr/local/Cellar/python/2.7.13 (6,337 files, 86.7MB)
  Built from source on 2017-04-29 at 21:05:41
/usr/local/Cellar/python/2.7.14 (6,344 files, 87.5MB)
  Built from source on 2017-09-29 at 11:58:30
/usr/local/Cellar/python/3.6.5 (4,820 files, 100.8MB)
  Poured from bottle on 2018-05-24 at 20:46:36
/usr/local/Cellar/python/3.6.5_1 (4,798 files, 100MB)
  Poured from bottle on 2018-06-29 at 23:19:01
/usr/local/Cellar/python/3.7.0 (4,916 files, 104.4MB)
  Poured from bottle on 2018-07-24 at 20:35:57
/usr/local/Cellar/python/3.7.1 (3,845 files, 59.6MB) *
  Poured from bottle on 2018-11-24 at 20:31:49
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
==> Dependencies
Build: pkg-config βœ”
Required: gdbm βœ”, openssl βœ”, readline βœ”, sqlite βœ”, xz βœ”
==> Options
--HEAD
    Install HEAD version
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

If you need Homebrew's Python 2.7 run
  brew install python@2

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 363,810 (30 days), 817,791 (90 days), 3,107,645 (365 days)
install_on_request: 219,127 (30 days), 523,966 (90 days), 1,889,556 (365 days)
build_error: 0 (30 days)

python@2: stable 2.7.15 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python@2/2.7.15_1 (4,670 files, 82.7MB) *
  Poured from bottle on 2018-11-28 at 18:28:59
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/[email protected]
==> Dependencies
Build: pkg-config βœ”, sphinx-doc ✘
Required: gdbm βœ”, openssl βœ”, readline βœ”, sqlite βœ”
==> Options
--HEAD
    Install HEAD version
==> Caveats
Pip and setuptools have been installed. To update them
  pip install --upgrade pip setuptools

You can install Python packages with
  pip install <package>

They will install into the site-package directory
  /usr/local/lib/python2.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 134,799 (30 days), 464,776 (90 days), 1,814,680 (365 days)
install_on_request: 30,368 (30 days), 89,538 (90 days), 354,231 (365 days)
build_error: 0 (30 days)
βœ” [brad@bradmac:~] $

@bradwood it's not enough information to reproduce. How do you install powerline?

Anyway, same error message doesn't mean it's same issue.
If you need to install powerline to reproduce, it's different issue.
If you can reproduce it without any external dependency, (only by :py3 print(42)), it's same issue.

that issue is still there boys...

brew install macvim

and :py3 print(42) breaks it

Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000117dc95c0 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.
uname -a
Darwin SpG.local 18.2.0 Darwin Kernel Version 18.2.0
18:45 ≑ mvim --version                                                                       ᴦ/ tmp ≑
VIM - Vi IMproved 8.1 (2018 May 18, compiled Dec 13 2018 12:07:57)
macOS version
Included patches: 1-577
Compiled by Homebrew
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +farsi             +mouse_sgr         -tag_any_white
+arabic            +file_in_path      -mouse_sysmouse    -tcl
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors
+autochdir         +float             +mouse_xterm       +terminal
-autoservername    +folding           +multi_byte        +terminfo
+balloon_eval      -footer            +multi_lang        +termresponse
+balloon_eval_term +fork()            -mzscheme          +textobjects
+browse            +fullscreen        +netbeans_intg     +timers
++builtin_terms    -gettext           +num64             +title
+byte_offset       -hangul_input      +odbeditor         +toolbar
+channel           +iconv             +packages          +transparency
+cindent           +insert_expand     +path_extra        +user_commands
+clientserver      +job               +perl              +vartabs
+clipboard         +jumplist          +persistent_undo   +vertsplit
+cmdline_compl     +keymap            +postscript        +virtualedit
+cmdline_hist      +lambda            +printer           +visual
+cmdline_info      +langmap           +profile           +visualextra
+comments          +libcall           -python            +viminfo
+conceal           +linebreak         +python3           +vreplace
+cryptv            +lispindent        +quickfix          +wildignore
+cscope            +listcmds          +reltime           +wildmenu
+cursorbind        +localmap          +rightleft         +windows
+cursorshape       +lua               +ruby              +writebackup
+dialog_con_gui    +menu              +scrollbind        -X11
+diff              +mksession         +signs             -xfontset
+digraphs          +modify_fname      +smartindent       +xim
+dnd               +mouse             +startuptime       -xpm
-ebcdic            +mouseshape        +statusline        -xsmp
+emacs_tags        +mouse_dec         -sun_workshop      -xterm_clipboard
+eval              -mouse_gpm         +syntax            -xterm_save
+ex_extra          -mouse_jsbterm     +tag_binary
+extra_search      +mouse_netterm     +tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -L.  -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -framework AppKit  -L/usr/local/opt/lua/lib -llua5.3 -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl  -L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin -lpython3.7m -framework CoreFoundation  -framework Ruby

@t0d0r Even though error is same, it must not be same issue. I don't have any trouble with same macvim.
Do you have any environment variable which break Python 3? Does python3 work fine?
What is env | grep -i python?

What do you see if you type set pythonthreehome? and set pythonthreedll?? Also, what's your Python version and how did you install them? Almost all Python problems ultimately come down to configuration issues and version mismatch so those information are usually useful to include.

Please don't recommend set pythonthreehome or set pythonthreedll. It's hacker only option.

Homebrew macvim should work fine without PYTHONHOME environment variable and
set pythonthreehome, set pythonthreedll.
When it is used, and it's wrong, the crash happens.

And even when configured them right for now, it will be wrong when Python is upgraded.
Unless you can debug the issue, you should never use them.

Note that I’m asking for the results of set pythonthreedll?. The question mark is a syntax to query the option in Vim. Even if you don’t set it manually you should at least know what that option does when using Python in Vim.

@t0d0r Even though error is same, it must not be same issue. I don't have any trouble with same macvim.
Do you have any environment variable which break Python 3? Does python3 work fine?
What is env | grep -i python?

Hi @methane, today I executed brew upgrade and python "encoding" error appears again, looks like that issue is connected with python3 and possible some of my vim modules (I have vimwiki and janus)

Β» env | grep -i python returns nothing.

On my system I have python3 and python2:

Β» brew list | grep python
python
python@2

The problem goes away when I add this simple check on the top of my .vimrc
or when I uninstall the python3.

if has('python')
          echo 'there is Python 2.x'
endif

if has('python3')
          echo 'there is Python 3.x'
endif

I reduced it to

if has('python')
endif

If I change python to python3 in code above

I got:

Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x000000010bfec5c0 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.

using has("python") locks version to python 2, and this prevent vim from crashing...

:py3 print(42)

E837: This Vim cannot execute :py3 after using :python

Β» brew list python

/usr/local/Cellar/python/3.7.3/bin/2to3
/usr/local/Cellar/python/3.7.3/bin/2to3-3.7
/usr/local/Cellar/python/3.7.3/bin/easy_install-3.7
/usr/local/Cellar/python/3.7.3/bin/idle3
/usr/local/Cellar/python/3.7.3/bin/idle3.7
/usr/local/Cellar/python/3.7.3/bin/pip3
/usr/local/Cellar/python/3.7.3/bin/pip3.7
/usr/local/Cellar/python/3.7.3/bin/pydoc3
/usr/local/Cellar/python/3.7.3/bin/pydoc3.7
/usr/local/Cellar/python/3.7.3/bin/python3
/usr/local/Cellar/python/3.7.3/bin/python3-config
/usr/local/Cellar/python/3.7.3/bin/python3.7
/usr/local/Cellar/python/3.7.3/bin/python3.7-config
/usr/local/Cellar/python/3.7.3/bin/python3.7m
/usr/local/Cellar/python/3.7.3/bin/python3.7m-config
/usr/local/Cellar/python/3.7.3/bin/pyvenv
/usr/local/Cellar/python/3.7.3/bin/pyvenv-3.7
/usr/local/Cellar/python/3.7.3/bin/wheel3
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/ (2722 files)
/usr/local/Cellar/python/3.7.3/IDLE 3.app/Contents/ (8 files)
/usr/local/Cellar/python/3.7.3/lib/pkgconfig/ (3 files)
/usr/local/Cellar/python/3.7.3/libexec/bin/ (7 files)
/usr/local/Cellar/python/3.7.3/libexec/pip/ (701 files)
/usr/local/Cellar/python/3.7.3/libexec/setuptools/ (345 files)
/usr/local/Cellar/python/3.7.3/libexec/wheel/ (38 files)
/usr/local/Cellar/python/3.7.3/Python Launcher 3.app/Contents/ (16 files)
/usr/local/Cellar/python/3.7.3/share/man/ (2 files)

Β» brew list python@2

/usr/local/Cellar/python@2/2.7.16/bin/2to3-2
/usr/local/Cellar/python@2/2.7.16/bin/2to3-2.7
/usr/local/Cellar/python@2/2.7.16/bin/easy_install
/usr/local/Cellar/python@2/2.7.16/bin/easy_install-2.7
/usr/local/Cellar/python@2/2.7.16/bin/idle
/usr/local/Cellar/python@2/2.7.16/bin/idle2
/usr/local/Cellar/python@2/2.7.16/bin/idle2.7
/usr/local/Cellar/python@2/2.7.16/bin/pip
/usr/local/Cellar/python@2/2.7.16/bin/pip2
/usr/local/Cellar/python@2/2.7.16/bin/pip2.7
/usr/local/Cellar/python@2/2.7.16/bin/pydoc
/usr/local/Cellar/python@2/2.7.16/bin/pydoc2
/usr/local/Cellar/python@2/2.7.16/bin/pydoc2.7
/usr/local/Cellar/python@2/2.7.16/bin/python
/usr/local/Cellar/python@2/2.7.16/bin/python-config
/usr/local/Cellar/python@2/2.7.16/bin/python2
/usr/local/Cellar/python@2/2.7.16/bin/python2-config
/usr/local/Cellar/python@2/2.7.16/bin/python2.7
/usr/local/Cellar/python@2/2.7.16/bin/python2.7-config
/usr/local/Cellar/python@2/2.7.16/bin/pythonw
/usr/local/Cellar/python@2/2.7.16/bin/pythonw2
/usr/local/Cellar/python@2/2.7.16/bin/pythonw2.7
/usr/local/Cellar/python@2/2.7.16/bin/smtpd.py
/usr/local/Cellar/python@2/2.7.16/bin/smtpd2.7.py
/usr/local/Cellar/python@2/2.7.16/bin/smtpd2.py
/usr/local/Cellar/python@2/2.7.16/bin/wheel
/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/ (2255 files)
/usr/local/Cellar/python@2/2.7.16/IDLE.app/Contents/ (8 files)
/usr/local/Cellar/python@2/2.7.16/lib/pkgconfig/ (3 files)
/usr/local/Cellar/python@2/2.7.16/libexec/pip/ (701 files)
/usr/local/Cellar/python@2/2.7.16/libexec/setuptools/ (345 files)
/usr/local/Cellar/python@2/2.7.16/libexec/wheel/ (38 files)
/usr/local/Cellar/python@2/2.7.16/Python Launcher.app/Contents/ (17 files)
/usr/local/Cellar/python@2/2.7.16/share/man/ (3 files)
/usr/local/Cellar/python@2/2.7.16/share/python@2/ (315 files)

Β» vim --version

VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 18 2019 23:51:40)
macOS version
Included patches: 1-950
Compiled by [email protected]
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         -tag_any_white
+arabic            +file_in_path      -mouse_sysmouse    -tcl
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors
+autochdir         +float             +mouse_xterm       +terminal
-autoservername    +folding           +multi_byte        +terminfo
+balloon_eval      -footer            +multi_lang        +termresponse
+balloon_eval_term +fork()            -mzscheme          +textobjects
+browse            +fullscreen        +netbeans_intg     +textprop
++builtin_terms    -gettext           +num64             +timers
+byte_offset       -hangul_input      +odbeditor         +title
+channel           +iconv             +packages          +toolbar
+cindent           +insert_expand     +path_extra        +transparency
+clientserver      +job               +perl/dyn          +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           +python/dyn        +visualextra
+conceal           +linebreak         +python3/dyn       +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       +lua/dyn           +ruby/dyn          +windows
+dialog_con_gui    +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             -X11
+digraphs          +modify_fname      +smartindent       -xfontset
+dnd               +mouse             +startuptime       +xim
-ebcdic            +mouseshape        +statusline        -xpm
+emacs_tags        +mouse_dec         -sun_workshop      -xsmp
+eval              -mouse_gpm         +syntax            -xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
+extra_search      +mouse_netterm     +tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -framework AppKit   -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE

@t0d0r Please answer to @ychin 's question: What do you see if you type set pythonthreehome? and set pythonthreedll??

It's very hard for me to guess how exactly Homebrew installs software, and what changes has been made lately, but my todo list will be something like below.

Please, note that I use Homebrew for a few tools missing in MacPorts, so I can't answer the question if it was the choice of maintainers of python3 and python2 ports in Homebrew. Because of this, it's located in the non-standard place and non-standard settings are used. Also I use MacVim from GitHub and I'm happy with my environment.

Official MacVim distribution on GitHub is linked by default with /usr/local/Frameworks/Python.framework/Versions/3.7/Python and /System/Library/Frameworks/Python.framework/Versions/2.7/Python, and here you can check other locations it checks by default.

To-Do list:

  1. Locate Python2 and Python3 (as @t0d0r wrote two lists)
  2. Set pythondll, pythonhome, pythonthreedll and pythonthreehome as described in :help python of standard ViM configuration. (It's not a "hacky" way to do it, as these settings are well described and everyone may have his own environment).
  3. Share these changes with maintainers of MacVim port in Homebrew if you use Hombrew-only version (using PR or put them an issue). This is a standard procedure for any package distribution system to ask them first.
  4. Share these settings via pull request for this file if you're really sure that you use DEFAULT settings of the Homebrew and it will use everyone with DEFAULT settings and you use MacVim from the GitHub.

2. (It's not a "hacky" way to do it, as these settings are well described and everyone may have his own environment).

Note that many people set these options without well understanding.
In most case, python library knows its home. (Vim had ignored it and it caused troubles. But it had fixed already.)

So it's very rarely need to configure pythonhome and pythonthreehome. Recommending these options to people is harmful. It will cause trouble like this, especially Homebrew Python is used.

When both of macvim and python are installed from homebrew, pythondll and pythonthreedll should not be modified too.

In most case, python library knows its home

It's not true for Python (see this) without executing it first. Even guessing this by library path is unbelievable hard. Please, remember, that you need to count every environment where ViM is running, not only Homebrew or even macOS.

It's not true for Python (see this) without executing it first.

It's not true. The document says: "where prefix and exec_prefix are installation-dependent directories, both defaulting to /usr/local."
exec_prefix and prefix are configured when building Python. So you never need to configure
pythonhome unless you are using Python installed other location than it's configured.

I don't know homebrew and macports use binary package or not when it's prefix is customized
(other than /usr/local/ (homebrew) or /opt/local (macports)).
If they install binary package instead of building Python, you may need to configure pythonhome. But I'm not sure.

Anyway, most people doesn't customize these locations. Python is installed in configured location.

Please, remember, that you need to count every environment where ViM is running, not only Homebrew or even macOS.

Installing prebuilt Python to other location its configured is not common on Linux too.
On Windows, it's common to configure installation location when installing Python binary.

But, please, remember, this is macvim issue tracker. MacVim is not used on Windows "in most case".

Yes, and python settings are not MacVim invention, and maintainers of Homebrew port are different people, so you should probably ask there too.

As I said, MacVim checks few common default locations, and locations like /usr/local/Cellar/python@2 are not "default" for builds. If somethings has been changed "by default", you can add a PR for a file I mentioned before.

Yes, and python settings are not MacVim invention, and maintainers of Homebrew port are different people, so you should probably ask there too.

Homebrew doesn't recommend configuring pythonhome. Some people say "try set pythonhome=..." on random places.
So there are nothing to ask homebrew maintainers. What we can do is:

  • when we see people saying "I got "No module named 'encodings'", reply "check pythonhome or pythonthreehome is configured. If it is, remove the setting."
  • when we see some people advice "try set pythonhome=...", reply "don't do it, unless you're expert and you understand what the setting is doing exactly. Otherwise, you will get trouble later."

As I said, MacVim checks few common default locations, and locations like /usr/local/Cellar/python@2 are not "default" for builds. If somethings has been changed "by default", you can add a PR for a file I mentioned before.

It is not relating to pythonhome or pythonthreehome.
If you use prebuilt MacVim and you want to use Python installed some place,
you need to configure only "pythonthreedll" or "pythondll". No need
to configure other python settings.

According to this comment, problem is strictly related. That comment clearly shows that paths where python is are different than MacVim from GitHub is expected.

Configuration may be changed by a maintainer of an unofficial package (such as Homebrew's build), but official release expect other paths in this order:

for Python2:

  • /System/Library/Frameworks/Python.framework/Versions/2.7/Python (macOS default)
  • /usr/local/Frameworks/Python.framework/Versions/2.7/Python (Homebrew)
  • /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python (MacPorts)
  • /Library/Frameworks/Python.framework/Versions/2.7/Python (python.org)

for Python3:

  • /usr/local/Frameworks/Python.framework/Versions/3.7/Python (homebrew, default)
  • /opt/local/Library/Frameworks/Python.framework/Versions/3.7/Python (macports)
  • /Library/Frameworks/Python.framework/Versions/3.7/Python (python.org)

If you clearly want to set paths automatically, you may propose your PR to vim/vim, not to MacVim.

@eirnym these are not relating to pythonhome and pythonthreehome. Did you really read my comment?

Configuring pythondll and pythonthreedll is enough to change Python path.
pythonhome and pythonthreehome shouldn't be configured. They only make trouble in most case.

According to this comment,

He said ""encoding" error appears again,"
So, Python is loaded correctly. Vim knows correct Python path.
The error caused by wrongly configured pythonhome or pythonthreehome.
You're totally misunderstanding this problem.

@methane If you think it's enough, please, send an issue/PR to ViM, not to MacVim. MacVim is only using codebase of Vim, bringing a very little above it.

@eirnym What are you saying? I think there are no issue in Vim and MacVim which cause this error.
I had fixed the issue in Vim and MacVim caused this error: see this comment

Now this error is caused by manually configured set pythonthreehome=... settings or PYTHONHOME environment variable.
It is not issue of Vim or MacVim. It is issue of people who recommends such wrong settings.

I replied here just because YOU said "2. (It's not a "hacky" way to do it, as these settings are well described and everyone may have his own environment)."
It is hacky setting. 99.9% people must not set it. It makes troubles, instead of fixing troubles.

@methane, Thank you, I've saw your comment, but it addressees an another issue in Vim during configuration process.

"hacky" means not well documented, and these options are well documented. Nobody can't force people to read documentation first.

I agree, that many languages, including perl, ruby and python know their home. There's no python home settings in the initial commit I could reach on Github of if_python.c (updated for version 7.0001). Remembering how Bram is commenting and accepting changes (I use Vim since 4.0), there was a very strong reasons and discussion why you're allowed (and required) to set pythonhome and eventually pythonthreehome variables to configure library using vimrc file. MacVim has nothing to do with the Vim part,

Support for environment variables goes from languages themselves and Vim doesn't interfere: user environment is USER environment and Vim is not a tool to break user experience

With Cellar paths to the python, listed above by t0d0r, I bet Homebrew changed their path locations once again, as it's often happening. And all users set paths directly suffer. In case of MacVim, it had set both dll and home set by default, link to dll stayed, but home was moved. In this case, the better way to complain is PR to fix formula or Homebrew itself as your problem is very Homebrew-specific. This formula is maintained by other people, than people develop MacVim. However, you may add new paths to vimrc to make official binary build to be compatible for a while.

It'd be better for everybody if maintainers of formula would refresh default configs and check if works not only passes build phase.

With Cellar paths to the python, listed above by t0d0r, I bet Homebrew changed their path locations once again, as it's often happening.

Yes. Homebrew changes path all time they upgrade Python.

In case of MacVim, it had set both dll and home set by default, link to dll stayed, but home was moved.

MacVim/Vim doesn't set home by default since I fixed it last year.
Unless manually configure it, "no module named encoding" must not be happened.

In this case, the better way to complain is PR to fix formula or Homebrew itself as your problem is very Homebrew-specific.

I use macvim in Homebrew and I am not suffered by this problem since I fixed it in last year.
Nothing in Homebrew is wrong. What is wrong is user configuration.

You should wait to investigate what is wrong in @t0d0r 's environment.

Yes. Homebrew changes path all time they upgrade Python.
[...]
I use macvim in Homebrew and I am not suffered by this problem since I fixed it in last year.

So it's better to ask maintainers of formula rather than to write here.

Unless manually configure it, "no module named encoding" must not be happened.

It works indeed, thank you

So it's better to ask maintainers of formula rather than to write here.

What to ask? Maintainers don't do anything wrong, as far as I know.

@t0d0r please, take a new vimrc from #891, replace the default one (not yours) and test with your environment. It should work

What to ask? Maintainers don't do anything wrong, as far as I know.

they didn't test every time paths are changing. This is the primary reason I don't use Homebrew. It's very often when software breaks just because paths has been changed or some library was upgraded and it's incompatible with few apps and so on. But this talk is for another thread, if you interested in.

@t0d0r please, take a new vimrc from #891, replace the default one (not yours) and test with your environment. It should work

@eirnym Note that macvim from Homebrew and released from here (1-950) works fine with latest Homebrew Python 3.
I didn't noticed #891, but it isn't wrong. It is just redundant.

I think @t0d0r breaked his vim by his vimrc or PYTHONHOME environment variable. Not vimrc from MacVim.

@methane It could not work with Python2.

It's redundant for combination Python3 and Homebrew only.

I merged @eirnym's change to remove setting pythonhome. The issue is closed for now and this will be released in a week or so when snapshot 156 is released. Please re-open the issue if you think this doesn't fix the issue. Looking at this long thread it does look like some misconfiguration between pythonhome and pythondll but I haven't seen @t0d0r reply to the pythonhome question so it's hard to tell for sure.

Was this page helpful?
0 / 5 - 0 ratings