Using Python with Wine

Gerard Patel gerard.patel at
Tue Jan 15 19:23:44 CST 2002

I have finally succeeded in using Python to make test
applications. I find the idea pretty interesting to build
quick-and-dirty applications to test a specific api.
Here is how it can be done. 

Get from :  Python 2.1.1 for windows

Get from

Install python under Wine :
./wine -managed <path to python installer>Python-2.1.1.exe 

unzip the 3 additional packages under the Python directory
(c:\program files\python21)

add these 3 directories to the Python path.
The easier way is to create a dir.pth file in the main
Python directory containing :

c:\\Program Files\\Python21\\calldll
c:\\Program Files\\Python21\\npstruct
c:\\Program Files\\Python21\\dynwin

add the path to the main python directory to the Wine path.

launch python (the command line version, I did not try
the gui version) :

wine python

Here are some commands I tried (I edited out most
of the Wine Fixme and Err, and removed prompts) :

import windll

   (.... 1. Basic example)


    (1 is the value returned by MessageBox - success)

   (.... 2. more involved example, using buffers)

winmm.mciSendString(cstr('play c:\\sound\\welcome.wav'),0,0,0)

    (error 279)

import calldll
print calldll.read_string(buf)
Cannot use 'all' as the device name with the specified command. 

   (I fix line 516 of mci.c to return a correct error message
   and compile Wine, try again)

i = winmm.mciSendString(cstr('play c:\\sound\\welcome.wav'),0,0,0)
fixme:mci:MCI_LoadMciDriver Couldn't load driver for type WAVEAUDIO. 
If you don't have a windows installation accessible from Wine,
you perhaps forgot to create a [mci] section in system.ini  

print i

   (I had indeed commented out the waveaudio entry in my system.ini
   -> fix user error and try again)

winmm.mciSendString(cstr('play c:\\sound\\welcome.wav'),0,0,0)

   (well, the mci call returns 0 - success - the sound is not played 
   completely  - but that's another story :-//)

    (.... 3. complete example of testing a gui function : TextOut)

import windll
cstr = windll.cstring
gdi32    = windll.module ('gdi32')
import wingdi
import windc
import winwin
class test(winwin.python_window):
        style = winwin.WS_OVERLAPPEDWINDOW
        def WM_DESTROY (self, wparam, lparam):
                winwin.user32.PostQuitMessage (0)
        def WM_PAINT (self, wparam, lparam):
                dc = self.begin_paint()
                gdi32.TextOut(dc.handle,50,50,cstr("text output"),11)
if __name__ == '__main__':
        import msgloop
        w = test("test 1").create()

(in this example most of the code use calls to
higher level functions hiding somewhat the Win32
Api, except the api call, that uses the 'handle'
member of the dc object to access the Win32 object)

There is a Python error message when the gui app
terminates, however this is a problem with the
python system (it shows the same under WinNT, 
for example)

Note : don't begin command by spaces - Python interpreter
don't like it. Also, Python don't care for case but
Wine does, so writing 'mcisendstring' will fail, for

More information about the wine-devel mailing list