How can I install MacVim on OSX 12.5 and get it to run the REPL for Lisp?

Question:

Update: Due to a change in the default build of vim and a change in directory structure on MacOS 12.5 no longer having Python frameworks installed, SLIMV initiated REPL doesn’t work with vim of MacVim when installing Python3 version 3.10 and vim or MacVim. Now just a symlink in the brew directory structure fixes the problem. Original question follows:

I have installed MacVim on OS X 12.5 (Monterey) and have the Lisp highlighting working having installed Slimv into ~/.vim/pack/plugins/start/slimv. While the highlighting and auto paren management works fine from either MacVim launched from the Dock or vim from the Terminal, the system will not run the REPL, saying the version of vim is not enabled for python.

I installed vim via brew and the python option is enabled, confirmed with a check of –version. MacVim was installed in /applications via "brew install –cask macvim".

I have tried setting a PATH to include the brew directory with launchctl. I tried adding a directory clause to the MacVim .plist file to include the brew directory. Also tried modifying /etc/paths and added a file to /etc/paths.d without success.

Is there a setting in MacVim or vim that will point to the version of vim that brew loaded? Other recommedations to get the REPL working within vim?

User romainl, a kind stackoverflower asked that I add the –version output for vim. (I think it was for confirming the python capability so I isolated those lines.)

sholland@HHC ~ % which vim
/opt/homebrew/bin/vim
sholland@HHC ~ % echo $path
/opt/homebrew/bin /opt/homebrew/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /opt/X11/bin /Library/Apple/usr/bin
sholland@HHC ~ % vim --version 
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jul 25 2022 08:23:04)
macOS version - arm64
Included patches: 1-65
Compiled by GitHub Actions
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +find_in_path      +mouse_xterm       -tcl
+arabic            +float             +multi_byte        +termguicolors
+autocmd           +folding           +multi_lang        +terminal
+autochdir         -footer            -mzscheme          +terminfo
-autoservername    +fork()            +netbeans_intg     +termresponse
+balloon_eval      +fullscreen        +num64             +textobjects
+balloon_eval_term +gettext           +odbeditor         +textprop
+browse            -hangul_input      +packages          +timers
++builtin_terms    +iconv             +path_extra        +title
+byte_offset       +insert_expand     +perl/dyn          +toolbar
+channel           +ipv6              +persistent_undo   +transparency
+cindent           +job               +popupwin          +user_commands
+clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           +python/dyn        +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby/dyn          +wildignore
+cursorbind        +lua/dyn           +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con_gui    +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            -X11
+digraphs          +mouse             -sound             -xfontset
+dnd               +mouseshape        +spell             +xim
-ebcdic            +mouse_dec         +startuptime       -xpm
+emacs_tags        -mouse_gpm         +statusline        -xsmp
+eval              -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary        
-farsi             -mouse_sysmouse    -tag_old_static    
+file_in_path      +mouse_urxvt       -tag_any_white     
   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 -arch x86_64 -arch arm64 -I/usr/local/Cellar/libsodium/1.0.18_1/include -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -Wall -Wextra -Wshadow -Werror -Wno-error=missing-field-initializers -Wno-error=deprecated-declarations -Wno-error=unused-function 
Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/[email protected]/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/[email protected]/lib -L/usr/local/opt/readline/lib -arch x86_64 -arch arm64 -L/usr/local/lib -o Vim -lm -lncurses /usr/local/lib/libsodium.a -liconv /usr/local/lib/libintl.a -framework AppKit -fstack-protector -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE

I think when Slimv executes it is picking the vim in /usr/bin. That vim does not have the python ability. Or maybe it just can’t find vim anywhere. –version for /usr/bin/vim below:

sholland@HHC ~ % /usr/bin/vim --version | grep python
+cmdline_hist      -langmap           -python            +viminfo
+cmdline_info      +libcall           -python3           +virtualedit

Extending on the above, I see I can do a :ver in vim. I also found there is a test for python availability. That gave an interesting result (run in the vim command mode):

:execute (has('python3') ? "python3" : "python") . " import sys; print(sys.version)"

E370: Could not load library /System/Library/Frameworks/Python.framework/Versions/2.7/Python: dlopen(/System/Library/Frameworks/Python.fra
mework/Versions/2.7/Python, 0x0009): tried: '/System/Library/Frameworks/Python.framework/Versions/2.7/Python' (no such file), '/Library/Fr
ameworks/Python.framework/Versions/2.7/Python' (no such file)
E263: Sorry, this command is disabled, the Python library could not be loaded.


:ver
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jul 25 2022 08:23:04)
macOS version - arm64
Included patches: 1-65
Compiled by GitHub Actions
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +dialog_con_gui    +jumplist          +multi_byte        +sodium            +vertsplit
+arabic            +diff              +keymap            +multi_lang        -sound             +vim9script
+autocmd           +digraphs          +lambda            -mzscheme          +spell             +viminfo
+autochdir         +dnd               +langmap           +netbeans_intg     +startuptime       +virtualedit
-autoservername    -ebcdic            +libcall           +num64             +statusline        +visual
+balloon_eval      +emacs_tags        +linebreak         +odbeditor         -sun_workshop      +visualextra
+balloon_eval_term +eval              +lispindent        +packages          +syntax            +vreplace
+browse            +ex_extra          +listcmds          +path_extra        +tag_binary        +wildignore
++builtin_terms    +extra_search      +localmap          +perl/dyn          -tag_old_static    +wildmenu
+byte_offset       -farsi             +lua/dyn           +persistent_undo   -tag_any_white     +windows
+channel           +file_in_path      +menu              +popupwin          -tcl               +writebackup
+cindent           +find_in_path      +mksession         +postscript        +termguicolors     -X11
+clientserver      +float             +modify_fname      +printer           +terminal          -xfontset
+clipboard         +folding           +mouse             +profile           +terminfo          +xim
+cmdline_compl     -footer            +mouseshape        +python/dyn        +termresponse      -xpm
+cmdline_hist      +fork()            +mouse_dec         +python3/dyn       +textobjects       -xsmp
+cmdline_info      +fullscreen        -mouse_gpm         +quickfix          +textprop          -xterm_clipboard
+comments          +gettext           -mouse_jsbterm     +reltime           +timers            -xterm_save
+conceal           -hangul_input      +mouse_netterm     +rightleft         +title
+cryptv            +iconv             +mouse_sgr         +ruby/dyn          +toolbar
+cscope            +insert_expand     -mouse_sysmouse    +scrollbind        +transparency
+cursorbind        +ipv6              +mouse_urxvt       +signs             +user_commands
+cursorshape       +job               +mouse_xterm       +smartindent       +vartabs
   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 -arch x86_64 -arch arm64 -I/usr/local/Cellar/libsodium/1.0.18_1/include -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -W
all -Wextra -Wshadow -Werror -Wno-error=missing-field-initializers -Wno-error=deprecated-declarations -Wno-error=unused-function
Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/[email protected]/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/[email protected]/lib
 -L/usr/local/opt/readline/lib -arch x86_64 -arch arm64 -L/usr/local/lib -o Vim -lm -lncurses /usr/local/lib/libsodium.a -liconv /
usr/local/lib/libintl.a -framework AppKit -fstack-protector -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE
Press ENTER or type command to continue

The interesting bit here is vim reports it has python and python3 enabled. However, the python test command errors out saying it couldn’t find the files.

Asked By: kd4ttc

||

Answers:

MacVim doesn’t have +python3, it has +python3/dyn which is quite different. See :help python-dynamic.

The former can be tested with:

:echo has('python3_dynamic')

while the latter can be tested with:

:echo has('python3')

The plugin you are trying to set up incorrectly tests for +python3:

if ( !exists( 'g:slimv_python_version' ) && has( 'python3' ) ) ||

which can’t work at all in MacVim, where has( 'python3' ) will always be false.

If you want to use that plugin, you have two options:

  • configure Vim properly and patch the plugin,
  • use a version of Vim that is built with +python3.
Answered By: romainl

The incredible answer above by @romainl got me to do a little hacking on my end and now MacVim and vim are working on MacOS 12.5.

The problem with running slimv on vim on mac is that the mac has dropped support for python frameworks. If you have installed vim with python support by using brew, vim and macvim will find the new version of python. However, vim and macvim currently look for Python3.9 rather than any Python3. The error message "Vim is compiled without the Python feature or Python is not installed. Unable to run SWANK client. Press ENTER to continue." is incomplete since the problem is not that Python3 is not installed, but rather that Python3.9 is not installed. Also, vim installed from brew has dynamic loading enabled. This fix is for when vim is compiled with dynamic python support.

  1. First, test your system to see if the problem is similar to what it was for me. You should have vim running and slimv installed. When editing a lisp file you will get parenthesis management working because you put slimv in the .vim folder as per directions. Escape into command mode and enter the two haracter sequence ",c". That is supposed to start up the REPL for Lisp. If you get the error "Vim is compiled without the Python feature or Python is not installed. Unable to run SWANK client. Press ENTER to continue" then this note applies.

  2. Check that your vim is in the brew directory and that vim was compiled with a dynamic version of python. The dynamic python versions are listed as +pythonx/dyn. To wit, running from your user directory in Terminal:

sholland@HHC ~ % which vim 
/opt/homebrew/bin/vim 
sholland@HHC ~ % vim --version | grep python
 +cmdline_hist      +langmap           +python/dyn        +viminfo
 +cmdline_info      +libcall           +python3/dyn       +virtualedit
  1. Check which version of Python is wanted. Do this by being in vim or MacVim in command mode enter

:execute ("python3") . " import sys; print(sys.version)"

  1. The error message should be E370: Could not load library. Also, you will find all the directories where vim tried to find Python3.

  2. Go to the Versions homebrew directory, such as /opt/homebrew/Frameworks/Python.framework/Versions in the Terminal. From step 4 determine the version of Python that vim wants. What you will do is create a symlink of the version that vim wants to the current version of Python. Alternatively you could install that version of Python3 from brew, but that is beyond the scope of this note. At the time I wrote this note you need a symlink from from 3.9 to current.

cd /opt/homebrew/Frameworks/Python.framework/Versions

ln -s ./Current 3.9

You should now be able to edit a lisp file in vim. Rerun the vim command :execute ("python3") . " import sys; print(sys.version)" and you will see the version of Python that is running. Now edit a Lisp file and ",c" should now start the SWANK server and you should get the split screen to run the REPL.

Now, the SLIMV documentation says you need the exact version that vim was built against. I have just hoped that version 3.9 differs little from the current version 3.10 that was installed on my system. If things fall apart in the future you may need to brew install version 3.9 or otherwise tweak these directions. I want to be able to upgrade my python to a latest version and let SLIMV run with that, thinking it is v3.9. I understand that vim will be linking to python3v10 in the future and will be requiring a specific version. Symlinks may need to be changed as vim changes the Python3 verson required.

Clearly, SLIMV and the brew install for python and vim as well as MacVim need to do some coordination. I have submitted bug reports to vim.org and to the author of SLIMV. They have done an incredible job with the software. Just a little change in Apple’s suport of Python and changes in the directory structure as well as vim making a change to the default options has caused two little problems. The software folks work hard to maintain compatibility, so the code may end up a little more comlex than what I hacked together here.

Looking forward to using Lisp with vim and a REPL!

Answered By: kd4ttc
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.