Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get my Vim and MacVim to find python3?

When I use a plugin that requires python, it can't find it and barfs.

The places that seem to being searched are:

enter image description here

Using -version I see both:

+python/dyn        
+python3/dyn

However :echo has("python3") returns 0.

I'm not sure if this is compile time config, or runtime-configurable via .vimrc.

I'm not a python developer, and the few times I've ventured into that world were in the middle of the python2/python3 mess that turned me off completely. I've played around enough to have configured pyenv it seems, and get

╰─$ which python
/Users/benlieb/.pyenv/shims/python

╰─$ python --version
Python 3.10.3

Can anyone help shed light on what to do to get python3 findable/usable in my vim?

Update:

Following @romainl's suggestion below I set in my .vimrc

set pythonthreedll=/Users/benlieb/.pyenv/shims/python

But getting the following error:

enter image description here

like image 792
pixelearth Avatar asked Oct 18 '25 13:10

pixelearth


2 Answers

After some time, I found the following works, thought it was not a fun path of discovery.

let &pythonthreedll = trim(system("pyenv which python"))
like image 181
pixelearth Avatar answered Oct 20 '25 01:10

pixelearth


+python/dyn and +python3/dyn are described here: :help python-dynamic.

By default, :help 'pythonthreedll' points to:

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

because MacVim is built against that version. The message in your screenshot says that there is nothing at that path. In order to have a working Python 3 interface, you can either:

  • install Python 3.10 via homebrew,
  • or point pythonthreedll to a valid path.

For example, I don't use Homebrew so the default value is useless to me, but I use MacPorts so this is my pythonthreedll:

set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib
like image 34
romainl Avatar answered Oct 20 '25 02:10

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!