How to Build Python 2.3.3 C/C++ Extensions in Windows Using Mingw32

C

C. Barnes

Normally, one uses the following procedure to build
and install a C/C++
extension:

python setup.py build --compiler=your_compiler
python setup.py install

For Python 2.3.3 on Windows, with the Mingw
(Minimalist GNU) compiler,
the following steps must be taken:

1. Find your Mingw bin directory. Copy gcc.exe to
cc.exe.

2. Get PExports from either of:

http://sebsauvage.net/python/pexports-0.42h.zip

http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip

Extract pexports.exe to your Mingw bin directory.

3. Find pythonxx.dll. It should be in your main
Python directory. Do
the following:

pexports python23.dll > python23.def
dlltool --dllname python23.dll --def python23.def
--output-lib libpython23.a

4. Copy libpythonxx.a to \python\libs.

5. Patch distutils. Locate
\python\lib\distutils\msvccompiler.py, open
it, and find the following lines (around line 211):

if len (self.__paths) == 0:
raise DistutilsPlatformError, \
("Python was built with version %s
of Visual Studio, "
"and extensions need to be built
with the same "
"version of the compiler, but it
isn't installed." % self.__version)

Delete these.

6. Move back to the directory of your extension. Do
the following:

python setup.py build --compiler=mingw32
python setup.py install


Ideally, only step 6 should be required to install an
extension.

I submitted the patch for step 5 to
python.sourceforge.net.
Steps 2-4 can be avoided if the libpythonxx.a file is
distributed
with Python. I'll email the Python folks and ask
them to do this.
Step 1 can probably be avoided with another patch.

This document is based on
http://sebsauvage.net/python/mingw.html,
which was written for Mingw + Python 2.2.

Thanks,
Connelly Barnes

PS:
To test this process, try compiling myspell-python, a
spell checking library for Python. See
http://oregonstate.edu/~barnesc/myspell-python-1.01.tar.gz





__________________________________
Do you Yahoo!?
Yahoo! Domains – Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer
 
A

Alejandro =?iso-8859-1?Q?L=F3pez-Valencia?=

R

Roger Binns

C. Barnes said:
5. Patch distutils. Locate
\python\lib\distutils\msvccompiler.py, open
it, and find the following lines (around line 211):

if len (self.__paths) == 0:
raise DistutilsPlatformError, \
("Python was built with version %s
of Visual Studio, "
"and extensions need to be built
with the same "
"version of the compiler, but it
isn't installed." % self.__version)

Delete these.

You don't need that. Do this instead:

python setup.py build --compiler=mingw32 bdist_wininst

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top