By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,271 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,271 IT Pros & Developers. It's quick & easy.

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

P: n/a

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/kern...orts-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/mysp...on-1.01.tar.gz

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

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2004-05-20, C. Barnes wrote in <ma*************************************@python.or g>:

2. Get PExports from either of:
This is awfully outdated.

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

http://starship.python.net/crew/kern...orts-0.42h.zip

Extract pexports.exe to your Mingw bin directory.


Rather go to http://mingw.org/ and download the mingw-utils package.
Hopefully that's the same place you obtained your compiler, linker and
libraries.

A better writer wants to submit a patch for the distutils manual?

--
Alejandro López-Valencia
qenqhy ng rgo qbg arg qbg pb http://dradul.tripod.com/
\u864e\u306e\u795e\u6bbf
Jul 18 '05 #2

P: n/a
C. Barnes wrote:
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
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.