Python Win32 binary building and x64 cross compiling on 32bit platform¶
Preparing Windows build environment¶
Build target system¶
Python-2.7 for windows x86, x64
(or Python-2.6)
Required Operating system¶
Windows XP SP3 32bit version
Required installations¶
Python-2.7.3 (x86) for windows
VisualC++ 2008 Express SP1 (VS2008SP1ENUX1512962.iso)
Windows SDK 2008 (6.0.6001.18000.367-KRMSDK_EN.iso)
Required extra library¶
Python-2.7 for amd64's
libs
directory for cross-link.
Install¶
Install
VisualC++ 2008 Express SP1
.Install
Windows SDK 2008
.Install
Python-2.7.3 x86
intoC:\Python27
(or anywhere).Place Python-2.7.3 amd64's
libs
intoC:\Python27\libs-amd64
.
Sample code¶
C:\temp\setup.py
:
from distutils.core import setup, Extension
setup(
name='spam',
version='0.1',
ext_modules=[Extension('spam', ['spam.c'])],
)
C:\temp\spam.c
:
#include <Python.h>
static PyMethodDef spam_methods[] = {
{NULL} /* Sentinel */
};
PyMODINIT_FUNC
initspam(void)
{
PyObject* m;
m = Py_InitModule("spam", spam_methods);
}
Build python module¶
for x86¶
First, invoke Windows SDK's CMD Shell
from Start -> Microsoft Windows SDK v6.1 -> CMD Shell
and do following:
C:\tmp> setenv /x86 /release
C:\tmp> set libpath=dummy
C:\tmp> python setup.py build
Finally, you get spam.pyd
for x86 architecture in build\lib.win32-2.7
.
注釈
Python2.7 distutils requires the libpath
environment variable (msvc9compiler.py Line 255).
But libpath is not used (msvc9compiler.py Line 371).
for x64¶
First, invoke CMD Shell
and do following:
C:\tmp> setenv /x64 /release
C:\tmp> set libpath=dummy
C:\tmp> python setup.py build --plat-name=win-amd64 build_ext --library_dirs=C:\Python27\libs-amd64
Finally, you get spam.pyd
for x64 architecture in build\lib.win-amd64-2.7
.
注釈
If you have x64 OS and Python amd64 installed, you can use python setup.py build command without options to build x64 binary.
References¶
https://github.com/python-imaging/Pillow/issues/28
This discussion gave me a important knowledge to making x64 build environment. Thanks adrianer.
5.4. Cross-compiling on Windows (In Japanese)
This article introduce "download Python source code and cross-compiling to get x64 libraries". I did not this, I copied
libs
directory from other operating system instead that was installed Python x64 version.msvc9compiler.py: ValueError when trying to compile with VC Express
This issue describe VisualStudio 2008 Express related problem. It was not reproduced on my environment (clean WinXP SP3 on virtual machine).
64BitCythonExtensionsOnWindows - Cython Wiki
This article introduce Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 but it is not worked for me. Windows7 SDK install VC9 related directory and compilers that does not fit to Python2.7.
Preparing Windows build environment - PyWavelets Documentation
つまみぐいプログラミング MinGW64でPython拡張モジュールを64bit向けにビルドする
This article introduce Python x64 binary building by using MinGW64. Indeed, I got a x64 (PIL's) pyd file but it did not work propery (cause bus error or else).
Re: How to receive a FILE* from Python under MinGW?
This discussion describe:
Problem is (AFAICT) that Python 2.4 uses a different version of the C runtime DLL (MSVCRT*.DLL) to that which MinGW links against. And it turns out that the different C runtime libraries have incompatible implementations of the FILE struct. And therefore if you try to pass a FILE* (fileno?) from Python to MinGW you will get a segfault.
At the time I read this, I stop looking for ways to use MinGW for 64bit build.