Browse files

- README file and improvements for Windows builds, thanks to…

… Jarek Zgoda
  • Loading branch information...
Jajcus committed Oct 14, 2005
1 parent 16884e6 commit c16517b23bca5ea44921948f37ebd8437406e17f
Showing with 55 additions and 2 deletions.
  1. +45 −0 README.WIN32
  2. +10 −2
@@ -0,0 +1,45 @@
Notes on how to compile Python extensions on windows without the Microsoft compiler. I assume some basic skills in Windows. Most of this is simply copied from


1. Get and install MinGW gcc
2. Create libpython2?.a
3. Get and install required libxml2 libraries and dependencies.
4. Compile/install the extension with distutils.

Get and install MinGW gcc
Get MinGW gcc from (Minimalist GNU For Windows). The only required packages are MSYS and msysDTK.

Create libpython2?.a
To create Python extensions, you need to link against the Python library. Unfortunately, most Python distributions are provided with Python2?.lib, a library in Microsoft Visual C++ format. GCC expects a .a file (libpython2?.a to be precise). Here's how to convert python2?.lib to libpython2?.a:

1. Download pexports from
2. Extract files and make sure the bin directory is in your path.
3. Locate Python2?.dll (Found mine under C:\WINNT\system32).
4. Run:

pexports python2?.dll > python2?.def

This will extract all symbols from python2?.dll and write them into python2?.def.
5. Run:

dlltool --dllname python2?.dll --def python2?.def --output-lib libpython2?.a

This will create libpython2?.a (dlltool is part of MinGW utilities).
6. Copy libpython2?.a to {your install}\python2?\libs\ (in the same directory as python22.lib). This trick should work for all Python versions, including future releases of Python. You can also use this trick to convert other libraries. (Will see about that soon)

Get and install required libxml2 libraries and dependencies
Download Win32 binaries for libxml2, zlib and iconv from Unpack the archives preserving directory structure and put them into some directory (e.g. d:\libs). If you exctract the libs in another directory, you will need to supply its locations to distutils ( script).
As libxml2 comes with .lib compiled for MSVC, you must create .a import library just the same as in case of libpython2x.a and put resulting libxml2.a in the same directory as libxml2.lib exists.

Compile/install the extension with distutils
Compile it:
python build -cmingw32
Install it:
python install --skip-build
Make binary distribution
python build -cmingw32 bdist_wininst
@@ -21,15 +21,23 @@
if python_only:
ext_modules = None
# set reasonable defaults, just in case
if sys.platform == 'win32':
include_dirs = [r'd:\libs\include', r'd:\libs\include\libxml']
library_dirs = [r'd:\libs\lib']
include_dirs = ['/usr/include/libxml2','/usr/local/include/libxml2']
library_dirs = []
ext_modules = [
libraries = ['xml2'],
include_dirs = ['libxml2addon','/usr/include/libxml2','/usr/local/include/libxml2'],
extra_compile_args = ['-g2'],
library_dirs = library_dirs,
include_dirs = include_dirs,
extra_compile_args = [],

0 comments on commit c16517b

Please sign in to comment.