-
-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macvim does not find standard macOS python3 #1351
Comments
Hmm, currently MacVim is configured to look for Homebrew Python, as that's the most popular version. I guess I can add a fallback to look for the Xcode Command-Line Tools one as well as that's another possible way people would have Python installed. I wouldn't say the default is wrong though. Homebrew is the most popular package manager for macOS and for installing the most-up-to-date Python version. One issue with the Xcode command-line tools version is that as usual, Apple bundles an old version of Python. The one you have is 3.9, but MacVim binary was linked against 3.10 (the next version that will be released soon will likely be linked against 3.11). Usually things will still work but there may be minor inconsistency that could happen if you have a mismatched Python version. For now, you can add this line to your vimrc which will make it use the version you want. Ultimately it's impossible for MacVim to know which one you want so it never hurts to explicitly state it:
I will think about whether to add that to the list of fallback paths we search for in MacVim's default search paths for Python 3. |
Great answer, everything makes sense to me. When I wrote that the default path is wrong, I meant that it looks for By the way, the same python problem arises if Macvim is installed via Homebrew but without having installed python before. It also happens when python3.10 is installed by Macports but not set as default python. Now the main problem as you explained is that Macvim is linked to a particular version of python (a typical package manager problem). I see two possible solutions to this:
In both cases, I would suggest adding some documentation to the Macvim help (and to the macvim website) on this subject. Is Python an isolated case, or are there other things that Macvim links to that expect the Homebrew version ? |
I would much rather have MacVim link with the Homebrew Python because as I said that's the more popular version as far as I understand. It's also much newer (it now has 3.11, which was released recently), which I prefer. I also want to point out that the problem with
Yeah I have some plans to make the docs / error message clearer. I do have to point out that this is not a MacVim-specific problem. Python support is built in to Vim, and the
The other scripting languages are also all dynamically linked. They are usually less annoying because their library paths aren't explicitly versioned like in Python. In Vim, scripting languages can be either statically or dynamically linked, and MacVim is using the dynamic route to allow using the |
Python automatic detection is here https://github.com/macvim-dev/macvim/blob/master/src/MacVim/vimrc. If MacVim haven't found homebrew's python, It tries to detect it from MacPorts and from official installation. |
Btw @dlejay I'm currently working on better/more flexible Python integration for Vim. Do you mind telling me what type of plugins you are using that require Python? I'm doing some casual testing and curious what plugins people are using that actually require Python. In particular, some of the previously popular plugins like denite and deoplete have migrated to newer plugins (in this instance ddu.vim) which don't use builtin Python anymore, so I just want to make sure I'm actually testing plugins people are using. |
I'll answer from my side: I use Python from MacPorts mainly 3.11, sometimes 3.10. Homebrew is not installed Plugins I use:
|
@ychin That would be :
|
Oh cool that's helpful. I knew about some of them but not others. FWIW with the change I'm working on you would be able to freely mix Python versions in the future so in this case for example it would be totally fine to use the Xcode Python 3.9 for a MacVim build (right now it kind of works but you really shouldn't, which is why I don't want to add the code to auto-detect Xcode's Python installation which is still on 3.9). |
@ychin Another thing to think about is those who use a homebrew installed python but use it in conjunction with virtualenv. For example, on my Apple Silicon mac laptop I have homebrew with python3: ❯ /opt/homebrew/bin/python3 --version
Python 3.11.2
❯ echo $VIRTUAL_ENV
$HOME/virtualenv
❯ $HOME/virtualenv/bin/python3 --version
Python 3.11.2
# symlink hack to get python3 support in MacVim
❯ pwd
/Library/Frameworks/Python.framework/Versions/3.10
❯ ls -alrth Python
lrwxr-xr-x root wheel 39 B Mon Mar 20 13:40:49 2023 Python ⇒ $HOME/virtualenv/bin/python
# Here is where the Xcode python is installed
❯ /Applications/Xcode.app/Contents/Developer/usr/bin/python3 --version
Python 3.9.6 |
Right. In your case though, couldn't you use Homebrew to install the exact version of Python to use? (Instead of I'm also not understanding why you need to symlink Python. You just directly set Either way, once we get Python 3 stable ABI support I think we can make the detection smarter as we will be guaranteed to work across Python versions. I happen to have a PR on Vim (vim/vim#12032) to solve this issue once and for all but it's been not getting much traction. You should go voice your support :) Edit: I edited the comment because I forgot what this issue was about. |
@ychin Nice feature! Thank you for an inclusion |
Vim added support for using Python 3 stable ABI in 9.0.1776, which allows us to safely load Python libraries of a different version from what Vim was built against. Modify our CI to use that. This allows user to use whatever Python version they want as long as it's above the minimum target. Given that macOS/Xcode still ships with 3.9 by default, we build using 3.9 as the minimum version. Also, change our Python detection script to work better. Change all explicit versions in our paths to refer to the "Current" version instead which for the most part should "just work" instead of requiring an exact match every time we or Python update to a new version (e.g. Homebrew will update the Current version to point to the latest Python3). Also add support for finding Python 3 from Xcode Command Line Tools which was previously not ok to use technically because it's 3.9 and before stable ABI support we couldn't load it safely as MacVim was built using newer versions. Fix macvim-dev#1351.
Steps to reproduce
xcode-select --install
:python3 --version
python3 --version
Expected behaviour
Macvim should find python, since it is installed by macOS.
Terminal.app replies
Python 3.9.6
Macvim looks for the wrong default path. I guess it's really looking for
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/Python3
Version of Vim and architecture
9.0, macOS, arm64
Environment
macOS Ventura 13.1
How MacVim was installed
Downloaded from GitHub
Logs and stack traces
Vim configuration where issue is reproducable
No response
Issue has been tested with given configuration
Issue has been tested with no configuration
mvim --clean
(orgvim
, supplied by MacVim distribution)vim --clean
(in terminal, supplied by MacVim distribution)vim --clean
(in terminal, other suppliers, e.g. /usr/bin/vim)Other conditions
The text was updated successfully, but these errors were encountered: