Welcome, guest | Sign In | My Account | Store | Cart

It is helpful to download and install precompiled binaries of Python modules especially for Windows. Second way is longer: get module sources, build the C compiler environment, compile binaries, beware of compiler warnings, install module.

Often precompiled binaries can be patched to meet used Python version.

See 'discussions' below for details.

Python, 64 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: Windows-1251 -*-
'''
find_dll_name.py

List all python dll names in DLL/PYD/etc file.

Author: Denis Barmenkov <denis.barmenkov@gmail.com>

Copyright: this code is free, but if you want to use it, 
           please keep this multiline comment along with source. 
           Thank you.

2009-08-09
'''
import re
import sys

fn = sys.argv[1]
f = open(fn, 'rb')
data = f.read()
f.close()

dll_re = re.compile(r'python\d\d\.dll', re.M | re.S)

found = dll_re.findall(data)

print found

#-------------- cut here -----------------#

# -*- coding: Windows-1251 -*-
'''
patch_dll_name.py

Patch extension precompiled binary by changing python dll name.

Author: Denis Barmenkov <denis.barmenkov@gmail.com>

Copyright: this code is free, but if you want to use it, 
           please keep this multiline comment along with source. 
           Thank you.

2009-08-09
'''

import sys
import os

OLD_NAME = 'python23.dll'
NEW_NAME = 'python24.dll'

fn = sys.argv[1]
f = open(fn, 'rb')
data = f.read()
f.close()

data = data.replace(OLD_NAME, NEW_NAME)

bak_fn = fn + '.bak'
os.rename(fn, bak_fn) # rename original file to .BAK

f = open(fn, 'wb')
f.write(data) # write patched version
f.close()

Sample of use

  1. Download ┬ÁTidylib, Python wrapper for HTML Tidy Library (tidy.sf.net). Binary path:

    http://download.berlios.de/utidylib/uTidylib-0.2.1.win32.exe
    
  2. Install it on Windows XP, try to execute sample code on Python 2.4:

    import tidy
    options = dict(output_xhtml=1, add_xml_decl=1, indent=1, tidy_mark=0)
    print tidy.parseString('<Html>Hello Tidy!', **options)
    

    get windows system DLL-not-found error: "Cant find python23.dll, please reinstall application, etc...."

  3. Go to installed module directory:

    C:\Python24\Lib\site-packages\tidy
    

    and search for precompiled binaries (usually files with extensions .DLL and .PYD):

    C:\Python24\Lib\site-packages\tidy\cygtidy-0-99-0.dll
    C:\Python24\Lib\site-packages\tidy\pvt_ctypes\_ctypes.pyd
    

    first are binary from Tidy HTML project itself, second is Python wrapper binary.

  4. List all the python*.dll occurrences in _ctypes.pyd file using first script:

    C:\Python24\Lib\site-packages\tidy\pvt_ctypes>find_dll_name.py _ctypes.pyd
    ['python23.dll']
    
  5. Patch binary with second script. New and old Python DLL names hardcoded in script for small size:

    patch_dll_name.py _ctypes.pyd
    
  6. Check for new name:

    C:\Python24\Lib\site-packages\tidy\pvt_ctypes>find_dll_name.py _ctypes.pyd
    ['python24.dll']
    
  7. Now it is possible to run ┬ÁTidylib sample:

    Source:

    import tidy
    options = dict(output_xhtml=1, add_xml_decl=1, indent=1, tidy_mark=0)
    print tidy.parseString('<Html>Hello Tidy!', **options)
    

    Results:

    <?xml version="1.0" encoding="us-ascii"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title></title>
      </head>
      <body>
        Hello Tidy!
      </body>
    </html>
    

4 comments

Denis Barmenkov (author) 12 years, 4 months ago  # | flag

Code html in discussion is broken a lot. Bug report created :)

Gabriel Genellina 12 years, 3 months ago  # | flag

This may work in very few and limited circumstances. The internal object layout, structures, data members, its sizes, used by the interpreter may change from one version to another. Even the C runtime library in use (e.g. MSVCRT71.DLL vs MSVCRT80.DLL) changes from one version to another. It's easy to crash the interpreter and even the whole system if you use the wrong library.

This recipe is extremely fragile and you should warn all users about the possible consequences in big red blinking words: DANGEROUS! USE AT YOUR OWN RISK!

Denis Barmenkov (author) 12 years, 3 months ago  # | flag

Thank you for attention.

It is worked for me about 15 times, no ugly symptoms :) But I prefer use Python 2.4.*

Gabriel Genellina 12 years, 3 months ago  # | flag

Do not abuse your good luck!