Compiling Ming for Python on Windows

April 26, 2006

Ming is a highly useful open-source Flash SWF writer that I am using in creating a Flash mapping application. However, it is only available as C source code and not Windows binaries, which is a pain if (like me) you work with an exclusively Windows-only environment and you have no Linux resources to hand. Trying to compile it can be a pain; the Windows environment is demanding enough, and it can be especially for Windows regulars who aren’t used to mucking around with Linux. To make it worse, there is precious little documentation around for it. So, for the benefit of anyone else interested in the same, here is how I managed to get the Ming modules for Python to work in Windows

1. Download & install Python 2.4 for Windows in e.g. c:/python
2. Download & install Cygwin in e.g. c:/cygwin. This provides you with a shell and other tools. When it comes to picking the modules and applications to use, add in autoconf, bison and flex. Do not install gcc or make – these are taken care of in the next step.
3. Download & install MinGW in e.g. c:/mingw. MinGW is not Ming – MinGW is an entirely different application takes care of the compilation.
4. Download the MinGW-zlib library. Copy the two .h files in usr/include/mingw to c:/mingw/include
5. Copy the file libpython24.a from c:/python/libs to c:/mingw/lib.
6. Download & install the Ming source code, in e.g. c:/ming
7. Download the source code for zlib. Copy the files zlib.h and zconf.h into c:/ming/src
8. Fire up Cygwin and go into the ming directory (e.g. cd /cygdrive/c/ming)
9. Type the following commands:

  $ autoconfig
  $ ./configure
  $ cd src
  $ mingw32-make static
  $ cd ..
  $ ls libming.a

10. A file called libming.a should now exist. Type cd py_ext and press ENTER.
11. In this folder, there should be a file setup.py. Open it, delete the existing code and replace it with:

from distutils.core import setup, Extension

setup(name = "mingc",
      version = "0.4",
      description = "A library for creating Flash files",
      py_modules = ['ming', 'mingc'],
      ext_modules = [Extension(name="_mingc",
                               sources=["ming_wrap.c"],
                               include_dirs=['/usr/local/include', '../src'],
                               library_dirs=['/usr/local/lib', '..'],
                               libraries=['ming'])])

12. Run the following command:

$ ../../python/python setup.py build --compiler=mingw32

(The path to your python instance may be different from the above)
13. In the folder build/lib.win32-2.4 there should now be a spanking new file _mingc.pyd.
14. You can test this by moving the file _mingc.pyd up two levels, in the same folder as shape.py, then running:

$ ../../Python/python shape.py

15. This should have created an SWF called test.swf, which consists of a red quarter-circle with a grey border.

References: When coming up with the above, I found this newsgroup post and this MinGW introduction page useful resources.

Advertisements

6 Responses to “Compiling Ming for Python on Windows”

  1. Moses Says:

    I was following your step until No.9…

    but the result is :
    “$ autoconfig
    bash: autoconfig: command not found”

    would you like to tell me that how to do it now ?

    thanks a lot!!!

  2. Oana Says:

    Hi,
    I’m trying to do the same thing.
    Is not autoconfig is autoconf.
    And I hope you add it (see step 2) when you were installing Cygwin or otherwise it will not work.
    I’m having a problem now with ./configure. It requests Freetype installed.
    When I’m finishing with this building I’ll public on the net so other will not have to go through this (like I did..).
    Ciao!

  3. equeenox Says:

    I have to put libz.a and libz.dll.a in the same folder with libming.a

    and then change the setup.py as following

    from distutils.core import setup, Extension

    setup(name = “mingc”,
    version = “0.4”,
    description = “A library for creating Flash files”,
    py_modules = [‘ming’, ‘mingc’],
    ext_modules = [Extension(name=”_mingc”,
    sources=[“ming_wrap.c”],
    include_dirs=[‘/usr/local/include’, ‘../src’],
    library_dirs=[‘/usr/local/lib’, ‘..’],
    libraries=[‘ming’,”z”])])

    then i copy the _mingc.pyd to python\dlls
    and copy the ming.py and mingc.py to python\Lib\site-packages

    I also need to make mgwz.dll (mingw32 dll) accessible to the the py script that uses ming package

  4. nahuel Says:

    Hi!, following your steps i get this message:

    error: You must have freetype installed; see http://www.freetype.org/

    i download the official package (included in cygwin) of freetypes but i can’t build it.

    Any tutorial, how to, or whatever?

  5. Diogo Says:

    6. Download and install the Ming source, eg in c: / ming. Not have the link to download this code Ming, where can I download it in order to install.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: