473,326 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

building extensions for Windows Python

JW
I have a lousy little Python extension, generated with the generous help
of Pyrex. In Linux, things are simple. I compile the extension, link it
against some C stuff, and *poof*! everything works.

My employer wants me to create a Windows version of my extension that
works with the vanilla Python 2.5 from python.org.

My employment contract states that I won't be required to run Windows, and
I desperately want to honor that clause. Ideally, I'd somehow MinGw cross
compile like I do with C/C++ and *poof*!, out would pop a file I could
hand out to someone who wanted to "import <my_lousy_extension>".

In Windows, things aren't so simple. I'm immediately bedazzled by a vast,
unfamiliar nomenclature: "VC6", "VC7.1", "msvcrt", "msvcr71", "msvcr80",
"VS2005", "VS2007", "MSVC2003", "MSVC2005", "Express Edition", ".NET SDK",
etc.

The python.org "recommended compiler" is apparently no longer
available, but someone posted a link to an obscure Microsoft webpage
artifact where it could still be obtained. Running it under WINE is less
than ideal, but I decided to try and make it work. However, when I tried
installing the compiler, it failed because my "Internet Explorer [was] out
of date." I'm not sure how IE comes into the picture, but I'm just a
programmer, after all.

I am further confused by the python.org docs on using MinGw to build
extensions: "These instructions only apply if you're using a version of
Python prior to 2.4.1 with a MinGW prior to 3.0.0", but further on:
"pcexports python25.dll >python25.def" seems to contradict that. It
really makes no difference. The referenced webpage where the "pcexports"
tool is found seems defunct.

My main problem is that I don't really grasp the big picture. Can someone
give me an overview of the requirements to build extensions for Windows
Python, circa 2.5? Or, can I tell my employer she'll just have to
hire/contract a Windows expert to do the mud wrestling?

Jim Wilson
Gainesville, FL
Oct 13 '06 #1
6 2209

JW wrote:
>
My main problem is that I don't really grasp the big picture. Can someone
give me an overview of the requirements to build extensions for Windows
Python, circa 2.5? Or, can I tell my employer she'll just have to
hire/contract a Windows expert to do the mud wrestling?

Jim Wilson
Gainesville, FL
To build an extension that runs on a generic python 2.5 you need a
Windows OS (suprise!) and VS.NET 2003. Some people may have had some
success with MinGW32 (on windows) but it's not going to work
'out-of-the-box'.

If your code is straightforward crossplatform C, you could setup a
distutils configuration script and pass it off to someone else to build
the windows binaries, but chances are some debugging will have to be
done.

Oct 13 '06 #2
On Fri, 2006-10-13 at 11:39 -0400, JW wrote:
I have a lousy little Python extension, generated with the generous help
of Pyrex. In Linux, things are simple. I compile the extension, link it
against some C stuff, and *poof*! everything works.

My employer wants me to create a Windows version of my extension that
works with the vanilla Python 2.5 from python.org.

My employment contract states that I won't be required to run Windows, and
I desperately want to honor that clause. Ideally, I'd somehow MinGw cross
compile like I do with C/C++ and *poof*!, out would pop a file I could
hand out to someone who wanted to "import <my_lousy_extension>".
I took a very simple pyrex file that compiled and worked fine on linux
and built it for windows using my mingw cross compiler.

First I borrowed a complete windows python installation and stuck it on
my linux drive (in my case in /usr/i386-pc-mingw32/Python2.4.

Then I just did:

$ pyrex test.pyx

$ i386-pc-mingw32-gcc -o test.dll test.c -I/usr/i386-pc-
mingw32/include/python2.4 -mwindows -shared -lpython24 -L/usr/i386-pc-
mingw32/Python2.4/lib

Since there were no special windows libraries used, there were no code
changes required at all. So look into the mingw cross compiler.
Usually you have to build it yourself. see
http://www.torriefamily.org/~torriem/cross for more information. The
information on the windows target is in the second half of the document.
This document used the OS X as the build host, but the same steps work
on linux. I prefer to use /usr/local or /usr as my prefix (ending up
with /usr/local/bin/i386-pc-mingw32-gcc etc)

Michael

>
In Windows, things aren't so simple. I'm immediately bedazzled by a vast,
unfamiliar nomenclature: "VC6", "VC7.1", "msvcrt", "msvcr71", "msvcr80",
"VS2005", "VS2007", "MSVC2003", "MSVC2005", "Express Edition", ".NET SDK",
etc.

The python.org "recommended compiler" is apparently no longer
available, but someone posted a link to an obscure Microsoft webpage
artifact where it could still be obtained. Running it under WINE is less
than ideal, but I decided to try and make it work. However, when I tried
installing the compiler, it failed because my "Internet Explorer [was] out
of date." I'm not sure how IE comes into the picture, but I'm just a
programmer, after all.

I am further confused by the python.org docs on using MinGw to build
extensions: "These instructions only apply if you're using a version of
Python prior to 2.4.1 with a MinGW prior to 3.0.0", but further on:
"pcexports python25.dll >python25.def" seems to contradict that. It
really makes no difference. The referenced webpage where the "pcexports"
tool is found seems defunct.

My main problem is that I don't really grasp the big picture. Can someone
give me an overview of the requirements to build extensions for Windows
Python, circa 2.5? Or, can I tell my employer she'll just have to
hire/contract a Windows expert to do the mud wrestling?

Jim Wilson
Gainesville, FL
Oct 13 '06 #3
JW <wi********@bellsouth.netwrote:
I have a lousy little Python extension, generated with the generous help
of Pyrex. In Linux, things are simple. I compile the extension, link it
against some C stuff, and *poof*! everything works.
;-)
My employer wants me to create a Windows version of my extension that
works with the vanilla Python 2.5 from python.org.

My employment contract states that I won't be required to run Windows, and
I desperately want to honor that clause. Ideally, I'd somehow MinGw cross
compile like I do with C/C++ and *poof*!, out would pop a file I could
hand out to someone who wanted to "import <my_lousy_extension>".
You can do that no trouble - we do. We use mingw on linux to compile
stuff for windows all the time. (We use the mingw package under
debian)

We build extensions using mingw but linked to the link library of the
official python2.4 build. The extensions then run with the standard
python.org install.

Here are some (slightly dated) instructions which you'll need to adapt
to your setup

/misc/windows is a smb mounted windows machine

# Linking with the distributed python
#
# http://bonsai.ims.u-tokyo.ac.jp/~mde...on/cygwin.html
#
# On a windows machine
# install the latest windows python (2.4.3.msi) from www.python.org
# Copy the header files into the mingw installation
cp -av /misc/windows/Python24/include /usr/i586-mingw32msvc/include/python2.4
# Download pexports from here
# http://www.emmestech.com/software/cy..._pexports.html
# unpack pexports.exe
unzip pexports-0.43.zip
# Fetch python dll from the windows machine
cp -av /misc/windows/WINNT/system32/python24.dll .
# Extract the exported symbols
wine pexports python24.dll python24.def
# Create the link library
/usr/i586-mingw32msvc/bin/dlltool --dllname python24.dll --def python24.def --output-lib libpython2.4.a
# Move the files into the correct place
mv -i python24.dll python24.def libpython2.4.a /usr/i586-mingw32msvc/lib/

After that lot you can build python extensions with mingw under linux,
using -lpython2.4 which will run under windows.

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Oct 14 '06 #4
ol*****@verizon.net <ol*****@verizon.netwrote:
To build an extension that runs on a generic python 2.5 you need a
Windows OS (suprise!) and VS.NET 2003. Some people may have had some
success with MinGW32 (on windows) but it's not going to work
'out-of-the-box'.
Neither of those statements are true. It is fairly easy to build
python extensions using mingw hosted on linux which work with the
standard python.org install - see my other post in this thread.

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Oct 14 '06 #5
JW
Thanks to Michael and Nick, I can now cross-compile my Pyrex extensions
for bog-standard Python 2.5. As I stumbled around in the dark trying to
bump into a solution, I was bolstered by the belief that at least two
other people had found the light at the end of the tunnel.

I had been using a crufty old prebuilt MinGW that linked to MSVCRT.DLL but
didn't include support for the newer VC runtime DLLs. I had to build the
current version which adds support for MVCR71 (used by Python 2.5) and
MSVCR80 (used by Microsoft's current ".NET" offering).

(Note: The build script proffered by mingw.org fails really cryptically if
you don't have the scanner tool, "flex", installed. But that's another
story. After some hand-to-hand combat, I had a working MinGW, nee GCC
3.4.2.)

Microsoft advises that it's very bad mojo to mix calls to MSVCRT.DLL and
MSVCR71.DLL in one application, but http://tinyurl.com/ydndnn (or a page
it references) advises how to avert such a disaster with a simple change
to MinGW's "spec" file (which I never knew existed).

The upshot is that I can now use Linux to cross-build my extension for
Windows, and my preliminary testing (under WINE -- See the original post.
I must adhere to my employment contract!) seems to show that it works.

Had I not known someone else claimed success, I would have thrown up my
hands in frustration.

Jim Wilson
Gainesville, FL

Oct 17 '06 #6
JW enlightened us with:
Thanks to Michael and Nick, I can now cross-compile my Pyrex
extensions for bog-standard Python 2.5 [...] I can now use Linux to
cross-build my extension for Windows, and my preliminary testing
(under WINE -- See the original post. I must adhere to my
employment contract!) seems to show that it works.
Congratulations!

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Oct 17 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Gonnerman | last post by:
I'll be quick. Here's a transcript: C:\usr\WConio-1.5>python setup.py build --compiler=mingw32 running build running build_py running build_ext building '_WConio' extension writing...
7
by: Carl Waldbieser | last post by:
I tried to adapt the instructions for building the M2Crypto module (http://sandbox.rulemaker.net/ngps/m2/INSTALL.html) to build a version compatible with Python2.3, but I've had some mixed results....
7
by: Anthony Baxter | last post by:
I'm trying to build a binary of fastaudio (the wrapper for the PortAudio library, from http://www.freenet.org.nz/python/pyPortAudio/) for Python 2.3. There's a lot of FAQs and the like out there...
1
by: Antoine Maillard | last post by:
Hi We're looking to make our own python modules for windows Python 23. We use swig and Visual Studio C++ for making the dlls. But when trying to compile, it says it's been missing a...
1
by: TPJ | last post by:
Hello, I have another, probably stupid, question. I'm working on some Python project, and I use some extensions written in C. I do all the development on my GNU/Linux box, so my setup.py script...
20
by: Thorsten Kampe | last post by:
Hi, I've already sent this to the Komodo mailing list (which seemed to me the more appropriate place) but unfortunately I got no response. I'd like to build a Python GUI app. Neither Tkinter...
4
by: vedrandekovic | last post by:
Hi, I have already install Microsoft visual studio .NET 2003 and MinGw, when I try to build a extension: python my_extension_setup.py build ( or install ) , I get an error: LINK : fatal...
3
by: kyosohma | last post by:
I am trying to figure out how to build binaries for Python packages and I've done it with MinGW. However, in my research, I've noticed that some of the programmers out there think that you should...
15
by: kyosohma | last post by:
Hi, I am trying to get a small group of volunteers together to create Windows binaries for any Python extension developer that needs them, much like the package/extension builders who volunteer...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.