Python2 support in MacVim bottle

(Wu Yongwei) #1


Would you please re-enable the Python2 support in the MacVim bottle? It is painful enough to see the Homebrew Python suddenly changed to Python3, and it is much more painful to see ClangComplete.vim stop working.

Actually I am having to revert to the old version, though I still have problems even after doing so. I have already had non-Homebrew Python3 installed, and it is a necessity that my C++ workflow can continue to work…

Best regards,


(Inada Naoki) #2

Have you read brew info macvim?
There is --with-python@2 option.

I’m strong -1 to make it default. Default should be Python 3.

BTW, clang_complete seems supportting Python 3 already.

(Wu Yongwei) #3

Thanks for the reply.

I have just found the clang_complete update too. But there could be other scripts that depend on Python2. I have not yet done a thorough search.

It does not need to be an either-or choice. I have also checked the official MacVim binary, and found it supports both python/dyn and python3/dyn. I.e. it supports both versions dynamically.

(Inada Naoki) #4

But it has own complexity & problems. (e.g. they can’t be used at same time. Which can be used is determined by which command is used first).
And Ubuntu’s vim is built with python3interp too. (while there is vim-py2 package).

Anyway, Python 2 will be die. I think efforts for removing Python 2 is worth than efforts for supporting it.

(Wu Yongwei) #5

Thanks. I was unaware of the technical constraint. (No such restrictions existed when I used Vim on Windows.)

When trying the Python3 build of MacVim with clang_complete, I encountered a strange error:

Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named ‘encodings’

Current thread 0x00007fff8924e340 (most recent call first):
Vim: Caught deadly signal ABRT
Vim: Finished.

I found the solution via Google, and these lines in .vimrc solved it:

if has('python3')
  set pythonthreehome=/usr/local/Frameworks/Python.framework/Versions/3.6

Do you know whether there is a better solution (like some tweaks to the MacVim formula)?

(Inada Naoki) #6

I use macvim bottle and I don’t need such hack.
I tried to mvim -u NONE -U NONE to skip all my local configuration, but
:python3 print("hello") works without any problem.

(Inada Naoki) #7

Maybe, you have some dirty environment variable?

(Wu Yongwei) #8

I do not know whether I have problems in my environment. After env -i PATH=$PATH mvim -u NONE -U NONE, I still could not execute any Python scripts. Apparently other people have encountered this issue:

Anyway, a workaround exists. Thanks for your reply!

(Inada Naoki) #9

I don’t know how it can happen without explicitly breaking environment.
But did you try brew upgrade, to synchronize python and vim build?

cd /usr/local/opt/macvim/
$ otool -L Vim | grep Python
	/usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/Python (compatibility version 3.6.0, current version 3.6.0)

(Wu Yongwei) #10

Python and MacVim were freshly upgraded (and they worked after I set pythonthreehome. The output of the otool command line is exactly the same as yours…

People mentioned installing MacVim from HEAD could solve the problem too, but that would require Xcode. Let us see whether the next version of MacVim could fix the problem automatically.

(Wu Yongwei) #11

BTW, set pythonthreehome=… is no longer needed as of MacVim 8.0-145_2.

(Inada Naoki) #12

I can reproduce the SIGTRAP now.

macvim: stable 8.0-146 (bottled), HEAD
python: stable 3.6.5 (bottled), devel 3.7.0b3, HEAD

MacVim 8.0-164 is built with Python 3.6.4_4, and Python is upgraded to 3.6.5.

(Inada Naoki) #13

I confirmed MacVim searches real prefix by dtruss:

stat64("/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/\0", 0x7FFF53AAADE0, 0x1B) = -1 Err#2
stat64("/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib\0", 0x7FFF53AAADE0, 0x1B) = -1 Err#2
stat64("/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6\0", 0x7FFF53AAADE0, 0x1B) = -1 Err#2

I tried to build simple program embedding Python. It searches opt_prefix instead of prefix.

stat64("/usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings\0", 0x7FFF554D7470, 0x7FFF554D7A78) = 0 0
stat64("/usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/\0", 0x7FFF554D70B0, 0x7FFF554D7A78) = 0 0
stat64("/usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/\0", 0x7FFF554D7830, 0x7FFF554D7A78) = 0 0


#include <Python.h>

main(int argc, char *argv[])
	printf("prefix = %ls\n", Py_GetPrefix());
	printf("path = %ls\n", Py_GetPath());
	printf("pyhome = %ls\n", Py_GetPythonHome());

	PyRun_SimpleString("from time import time,ctime\n"
			"print('Today is', ctime(time()))\n");
	if (Py_FinalizeEx() < 0) {
	return 0;

//  cc test.c `python3-config --cflags --ldflags`

I don’t know why MacVim searches prefix, instead of opt_prefix.

(Inada Naoki) #14

I found it. Vim’s configure script embeds sys.prefix, and vim calls Py_SetPythonHome() for it.

Original commit is this:

(Wu Yongwei) #15

So the gotcha is that python should be upgraded with macvim, but not before. :cold_sweat:

(Inada Naoki) #16

FYI, I created pull request to vim already.