0

On a vanilla MacBook with M1 processor, I installed MacVim via Homebrew:

brew install --cask macvim

However, when running :python import sys; print(sys.version) inside MacVim, I get:

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

I strangely can't find the right instructions based on the above error message, as I expect this problem to be quite common.

The cause is that macOS no longer ships with Python, but fixing it is not trivial. It seems that I'll need the right combination of a specific Python installation (Homebrew?) and the correct Vim configuration.

Does anyone know the exact setup and configuration instructions?

1
  • Report that as a bug to homebrew - they macvim formula should provide python as one of its requirements.
    – mmmmmm
    Commented Sep 1, 2022 at 6:22

2 Answers 2

2

The easy answer was apparently

brew install python
brew install [email protected]

and then it all works without extra Vim configuration.

5
  • Yes but note it is python 3 and also it is still a bug in Homebrew
    – mmmmmm
    Commented Sep 1, 2022 at 9:10
  • @mmmmmm Can a cask require dependencies that are part of homebrew-core? Honest question. That MacVim distribution is fundamentally broken anyway, all cask does is install binaries provided by someone else. Commented Sep 3, 2022 at 15:37
  • @Marc no-idea I use MacPorts and its Portfiles describe all the dependencies (well you need to look at PortGroup as well). For MacVIM macports gives various variants for different pythons rubies and perl and tcl
    – mmmmmm
    Commented Sep 3, 2022 at 15:40
  • @mmmmmm I use MacPorts as well. I note that MacVim by default there doesn't have any language dependency, they're all variants. Commented Sep 3, 2022 at 15:48
  • This solution did not work for me. I have the macvim homebrew cask, python2 and python3 installed via homebrew but still cannot execute python commands from macvim. Commented May 11, 2023 at 12:01
0

Apple no longer ships a version of Python 2.7. And does not ship a version of Python 3.x other than the one provided by the CLT. So there is no binary on your system for 2.7.

If you need python, either install the CLT, or install a distribution from python.org.

And then configure Vim to actually run it vs however it is currently configured.

2
  • And do not install a python version 2 as python.org made that obselete over 2 years ago
    – mmmmmm
    Commented Sep 1, 2022 at 6:21
  • @RubenVerborgh. As python.org made python 2 obsolete on 1/1/20 nearly a year before Apple released an Apple Silicon machine you can't get an official build of python 2 for Apple ARM. If you are asking these sorts of questions you need to do more research and understand why not just copy a script
    – mmmmmm
    Commented Sep 1, 2022 at 7:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .