Compiling Vim 7.2 with Python 3.0 on Windows XP

10 views
Skip to first unread message

Daniel Hast

unread,
Dec 21, 2008, 5:49:52 PM12/21/08
to v...@vim.org
I just started using Vim recently, and I've found it to be an extremely useful editor for Python. However, the self-installing Vim 7.2 executable is set up for use with Python 2.4, so it looks for python24.dll. Since it doesn't exist on my computer, I can't run any Python code in Vim. (Since Python 3.0 isn't backwards compatible, I can't just install Python 2.4, because then my programs wouldn't work.)

I downloaded the Vim 7.2 source from ftp://ftp.vim.org/pub/vim/pc/vim72src.zip and tried to compile it using MinGW, which I also just installed. I edited Make_ming.mak to add Python compilation options, specifically (right after the Python-related comment block):

PYTHON=c:/PROGRA~1/Python30
PYTHON_VER=30

I then tried to compile it using the following command:

mingw32-make -f Make_ming.mak gvim.exe

It successfully compiled most of the files using gcc, but when it tried to compile if_python.c, the following error occurred:

if_python.c: In function `PythonIO_Init':
if_python.c:951: error: structure has no member named `ob_type'
if_python.c: In function `PythonMod_Init':
if_python.c:2351: error: structure has no member named `ob_type'
if_python.c:2352: error: structure has no member named `ob_type'
if_python.c:2353: error: structure has no member named `ob_type'
if_python.c:2354: error: structure has no member named `ob_type'
if_python.c:2355: error: structure has no member named `ob_type'
if_python.c:2356: error: structure has no member named `ob_type'
mingw32-make: *** [gobj/if_python.o] Error 1

The compilation process then exited immediately. I tried this several times, each time with the same results. In if_python.c, at each of the lines mentioned in the above error message is a line like the following (where "[something]" is a variable name):

[something].ob_type = &PyType_Type;

What is causing this problem, and how can I compile Vim with Python 3.0? (I am using Windows XP, Vim 7.2, Python 3.0, MinGW 5.1.4, Make 3.81, and gcc 3.4.5.)

Thanks,
Daniel Hast

John Beckett

unread,
Dec 21, 2008, 8:32:33 PM12/21/08
to vim...@googlegroups.com
Daniel Hast wrote:
> I downloaded the Vim 7.2 source from
> ftp://ftp.vim.org/pub/vim/pc/vim72src.zip

You should patch it as well, and get the latest runtime. Patching is
quite easy, but it's a bit complex to describe (I'm hoping to do a wiki
page on it one day). I don't know a practical way to get the latest
runtime except by using rsync on a Unix-based system.

> if_python.c: In function `PythonIO_Init':
> if_python.c:951: error: structure has no member named `ob_type'

I don't know the details of what's going on, but ob_type is defined in a
Python header (look for a file like /Python30/include/object.h).
Somehow, the Vim compile is supposed to include object.h, or equivalent.
I'm giving this clue, in the hope that someone will explain what step
you are missing. Check how you are telling your compiler where your
Python is (try the make file).

John

pans...@routon.com

unread,
Dec 21, 2008, 9:10:05 PM12/21/08
to vim...@googlegroups.com, v...@vim.org, vim...@googlegroups.com
vim...@googlegroups.com 写于 2008-12-22 06:49:52:
> I just started using Vim recently, and I've found it to be an
> extremely useful editor for Python. However, the self-installing Vim
> 7.2 executable is set up for use with Python 2.4, so it looks for
> python24.dll. Since it doesn't exist on my computer, I can't run any
> Python code in Vim. (Since Python 3.0 isn't backwards compatible, I
> can't just install Python 2.4, because then my programs wouldn't work.)
>
> Thanks,
> Daniel Hast

Perhaps I've missed something, but as far as I know python3.0 is
incompatible with python 2.x and vim must be tailored towards Python 3.0
before it can compile with python 3.0.

Currently, vim is not designed to work with python 3.0 and it will not
compile on Python 3.0 unless you hack the vim code yourself to give it
python 3.0 support.

Please correct me if I'm wrong.
--
Regrads,
Pan, Shi Zhu

Daniel Hast

unread,
Dec 21, 2008, 11:22:48 PM12/21/08
to vim...@googlegroups.com
On Sun, Dec 21, 2008 at 8:32 PM, John Beckett <johnb....@gmail.com> wrote:

Daniel Hast wrote:
> I downloaded the Vim 7.2 source from
> ftp://ftp.vim.org/pub/vim/pc/vim72src.zip

You should patch it as well, and get the latest runtime. Patching is
quite easy, but it's a bit complex to describe (I'm hoping to do a wiki
page on it one day). I don't know a practical way to get the latest
runtime except by using rsync on a Unix-based system.
> if_python.c: In function `PythonIO_Init':
> if_python.c:951: error: structure has no member named `ob_type'

I don't know the details of what's going on, but ob_type is defined in a
Python header (look for a file like /Python30/include/object.h).
Somehow, the Vim compile is supposed to include object.h, or equivalent.
I'm giving this clue, in the hope that someone will explain what step
you are missing. Check how you are telling your compiler where your
Python is (try the make file).

John


I checked, and if_python.c includes Python.h, which includes object.h. The include statements aren't inside any conditional blocks, either. I edited the make file to add PYTHON=c:\PROGRA~1\Python30, which is my Python directory. It seems like object.h is running, as far as I can tell.

I got the latest runtime using AAP, and I applied all of the Vim 7.2 patches that apply to files that already existed. (I assume the other patches applied to different operating systems or something.)

I tried compiling it again, and the same thing happened, with the exact same error message. The only difference was that the line numbers given in the error message were slightly higher due to the patches.

2008/12/21 <pans...@routon.com>

Python 3.0 is incompatible with Python 2.x, but that shouldn't be a problem for Vim, since it's not written in Python. I edited the make file to use the Python 3.0 files and DLLs; as far as I know, those contain everything Vim should need for Python 3.0 support. I think that the only problems arise when a Python program uses syntax that doesn't work in 3.0 or calls functions that were removed or substantially changed, so C programs shouldn't be affected.

Daniel Hast

John Beckett

unread,
Dec 21, 2008, 11:59:17 PM12/21/08
to vim...@googlegroups.com
Daniel Hast wrote:
> I checked, and if_python.c includes Python.h, which includes
> object.h. The include statements aren't inside any
> conditional blocks, either. I edited the make file to add
> PYTHON=c:\PROGRA~1\Python30, which is my Python directory. It
> seems like object.h is running, as far as I can tell.


I haven't built Vim for a while. On the last occasion (Windows), I set
the following environment variables:

set GUI=yes
set DYNAMIC_PYTHON=yes
set PYTHON=C:/Python25
set PYTHON_VER=25

You could try copying your Python30 to C:\ although it's hard to see why
it should matter (given that your PYTHON path above has no embedded
space).

I would experiment with object.h. Perhaps rename it (to force a compile
error), or put '#error Hello' in first line and see what the compiler
says.

A very quick look at Vim's if_python.c makes me think that Python's
object.h needs to define:
PyObject_HEAD_INIT()

which should define ob_type. Hmmm, I have to go now, but a really quick
look at object.h makes me wonder if Py_TRACE_REFS is defined on your
system (I guess that it should NOT be). Or, maybe Python 3.0 has
different stuff in object.h?

John

Tony Mechelynck

unread,
Dec 22, 2008, 12:42:56 AM12/22/08
to vim...@googlegroups.com, v...@vim.org

IIUC, Vim expects the structure type PyTypeObject, defined in Python.h,
to have a member named ob_type. Any Python release notes or other docs
about what might have changed between 2.6 (where I compile this
interface with no error) and 3.0?

Best regards,
Tony.
--
If God had intended Men to Smoke, He would have put Chimneys in their
Heads.

pans...@routon.com

unread,
Dec 22, 2008, 1:22:19 AM12/22/08
to vim...@googlegroups.com
vim...@googlegroups.com 写于 2008-12-22 12:22:48:
> Python 3.0 is incompatible with Python 2.x, but that shouldn't be a
> problem for Vim, since it's not written in Python. I edited the make
> file to use the Python 3.0 files and DLLs; as far as I know, those
> contain everything Vim should need for Python 3.0 support. I think
> that the only problems arise when a Python program uses syntax that
> doesn't work in 3.0 or calls functions that were removed or
> substantially changed, so C programs shouldn't be affected.
>
> Daniel Hast

I had read python 3.0's release note and it clearly states that the C
interface to python is incompatible and all programs using the C interface
to python should be rewritten.

Since Vim uses python's C interface to integrate python, part of vim code
which interacts with python must be rewritten anyway.

Regards,
Pan, Shi Zhu

John Beckett

unread,
Dec 22, 2008, 1:29:20 AM12/22/08
to vim...@googlegroups.com
Google appears to have the answer, or at least the question.

Apparently Python 3.0 has a new interface. Someone needs to study this
and work out what the change means for Vim. For example, see:

http://bugs.python.org/issue4385
http://www.python.org/dev/peps/pep-3123/
http://www.mail-archive.com/pytho...@python.org/msg15045.html

John

Daniel Hast

unread,
Dec 22, 2008, 2:23:47 PM12/22/08
to vim...@googlegroups.com
Well, that would explain it. I didn't realize the C interface in 3.0 isn't backwards compatible, either. Unfortunately, although I have Python 2.6, many of my Python programs don't run on anything earlier than Python 3.0 now.

I don't know enough about C to figure out what needs to be changed in if_python.c, but it doesn't seem like there are very many changes that would be needed for it to work with Python 3.0. From what I understand of PEP 3123, anything using PyObject_HEAD_INIT needs to be converted to PyVarObject_HEAD_INIT, along with a few other changes relating to PyObject and PyVarObject.

Anyone more familiar with C know how complicated it would be to make these changes?

Daniel Hast

Roland.Puntaier

unread,
Jun 8, 2009, 4:27:31 AM6/8/09
to vim...@googlegroups.com

Please see the message:
Re: [ANN] vim patch to support python3 interface
at
http://tech.groups.yahoo.com/group/vimdev/message/54379
--
View this message in context: http://www.nabble.com/Compiling-Vim-7.2-with-Python-3.0-on-Windows-XP-tp21121227p23920154.html
Sent from the Vim - General mailing list archive at Nabble.com.

Reply all
Reply to author
Forward
0 new messages