How do I install vim on OSX with Python 3 support?

13,574

The version of Vim you're running is the built-in Apple version, which you can see in the second line ("Compiled by [email protected]"). You can install either the vim or macvim packages with Homebrew and they will have Python 3 built in, since, as ParthS007 mentioned, the default Python is Python 3.

However, your PATH environment variable will need to have /usr/local/bin before /usr/bin if you want to use the Homebrew version over the default system version (which you almost certainly do). You can edit your shell configuration to change the setting and then restart your terminal session.

If your PATH environment variable is set correctly, it's possible you may also have to run brew link vim (or brew link macvim) to create the appropriate symlinks. In general, you'll want command -v vim to show /usr/local/bin/vim. Running /usr/local/bin/vim by hand should show the correct Vim installed.

Share:
13,574
ecjb
Author by

ecjb

Blablablabla ... and Blabla

Updated on June 21, 2022

Comments

  • ecjb
    ecjb almost 2 years

    I have trouble installing vim with python 3 for MacOS. I'm aware that there is a similar similar question on that topic. but I couldn't solve the problem

    first I ran vim --version and got

    Included patches: 1-503, 505-680, 682-1283
    Compiled by [email protected]
    Normal version without GUI.  Features included (+) or not (-):
    +acl             +file_in_path    -mouse_sgr       +tag_old_static
    -arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
    +autocmd         +float           -mouse_urxvt     -tcl
    -balloon_eval    +folding         +mouse_xterm     -termguicolors
    -browse          -footer          +multi_byte      -terminal
    +builtin_terms   +fork()          +multi_lang      +terminfo
    +byte_offset     -gettext         -mzscheme        +termresponse
    +channel         -hangul_input    +netbeans_intg   +textobjects
    +cindent         +iconv           +num64           +timers
    -clientserver    +insert_expand   +packages        +title
    -clipboard       +job             +path_extra      -toolbar
    +cmdline_compl   +jumplist        -perl            +user_commands
    +cmdline_hist    -keymap          +persistent_undo +vertsplit
    +cmdline_info    +lambda          +postscript      +virtualedit
    +comments        -langmap         +printer         +visual
    -conceal         +libcall         -profile         +visualextra
    +cryptv          +linebreak       +python/dyn      +viminfo
    +cscope          +lispindent      -python3         +vreplace
    +cursorbind      +listcmds        +quickfix        +wildignore
    +cursorshape     +localmap        +reltime         +wildmenu
    +dialog_con      -lua             -rightleft       +windows
    +diff            +menu            +ruby/dyn        +writebackup
    +digraphs        +mksession       +scrollbind      -X11
    -dnd             +modify_fname    +signs           -xfontset
    -ebcdic          +mouse           +smartindent     -xim
    -emacs_tags      -mouseshape      +startuptime     -xpm
    +eval            -mouse_dec       +statusline      -xsmp
    +ex_extra        -mouse_gpm       -sun_workshop    -xterm_clipboard
    +extra_search    -mouse_jsbterm   +syntax          -xterm_save
    -farsi           -mouse_netterm   +tag_binary      
       system vimrc file: "$VIM/vimrc"
         user vimrc file: "$HOME/.vimrc"
     2nd user vimrc file: "~/.vim/vimrc"
          user exrc file: "$HOME/.exrc"
           defaults file: "$VIMRUNTIME/defaults.vim"
      fall-back for $VIM: "/usr/share/vim"
    Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
    Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa 
    

    which is the default vim version installed on my mac. Unfortunately, it says: -python3. So I assume python 3 is not installed. So what I did is the following:

    brew remove vim which went ok and then brew info vim and got the following message:

    vim: stable 8.1.1550 (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)
    Not installed
    From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/vim.rb
    ==> Dependencies
    Required: gettext ✔, lua ✔, perl ✔, python ✔, ruby ✔
    ==> Options
    --HEAD
        Install HEAD version
    ==> Analytics
    install: 89,945 (30 days), 222,053 (90 days), 835,730 (365 days)
    install_on_request: 82,933 (30 days), 204,131 (90 days), 747,520 (365 days)
    build_error: 0 (30 days)
    

    Is it because there are 2 versions of vim installed now?

    I also tried brew install vim --with-python3 but got the following message invalid option: --with-python3 when typing vim --version, I get:

    vim --version
    VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb 22 2019 19:03:04)
    Included patches: 1-503, 505-680, 682-1283
    Compiled by [email protected]
    

    EDIT

    Here are commands with their corresponding outputs

    • sudo nano /etc/paths:
    /usr/local/bin
    /usr/bin
    /bin
    /usr/sbin
    /sbin
    
    • command -v vim:
    /usr/bin/vim
    
    • $PATH:
    -bash: /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin: No such file or directory
    

    Moreover I posted a similar question on another platform and did many attempt to try solving the problem. However the problem still persists.

  • ecjb
    ecjb almost 5 years
    many thanks for your answer @bk2204. It appears to be already the case. Here what I get after the command sudo nano /etc/paths: /usr/local/bin /usr/bin /bin /usr/sbin /sbin. Moreover I posted a similar question on another platform and did many attempt (apple.stackexchange.com/questions/362833/…). However the problem still persists. Do you have another idea?
  • bk2204
    bk2204 almost 5 years
    What do you get when you run command -v vim and 'echo $PATH`?
  • ecjb
    ecjb almost 5 years
    Many thanks: @bk2204. I edited the question with requested command and corresponding outputs. Do you see where the problem could be?
  • AngularNerd
    AngularNerd over 2 years
    I had to add /opt/homebrew/bin to my /etc/paths. I put it 2nd after /usr/local/bin (Mac M1)