This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Allow compilation of C/C++ Python extensions without MSVC
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: connelly, loewis, theller
Priority: normal Keywords: patch

Created on 2004-05-19 20:37 by connelly, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
distutils.diff connelly, 2004-05-19 20:41
Messages (5)
msg46006 - (view) Author: Connelly (connelly) Date: 2004-05-19 20:37
This page describes how to compile C/C++ Python 
extensions with Mingw:

http://sebsauvage.net/python/mingw.html

This process works.  However, you need to patch 
Python to get the 'python setup.py install' step to work 
correctly.  This is the second step in installing a Python 
extension.

The first step: 'python setup.py build -cmingw32' works 
fine.
The second step: 'python setup.py install' fails with the 
following error:

"error: Python was built with version 6 of Visual Studio, 
and extensions need to
be built with the same version of the compiler, but it 
isn't installed."

This statement is factually untrue.  Python uses .pyd 
files to run Python extensions, which are actually .dll 
files, and are compatible across different compilers and 
compiler versions.

So open \Python\Lib\distutils\msvccompiler.py and 
remove the warning (it's around line 211).  

Or apply the patch:

--- msvccompiler.bak	Thu Dec  4 09:38:22 2003
+++ msvccompiler.py	Wed May 19 13:15:34 2004
@@ -208,11 +208,10 @@
             self.__root = r"Software\Microsoft\Devstudio"
         self.__paths = self.get_msvc_paths("path")
 
-        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)
+        # Note: Extensions CAN be built with Mingw32.
+        # See http://sebsauvage.net/python/mingw.html.
+        # The .pyd files created are DLLs, and these are 
compatible across
+        # different compilers and compiler versions.
 
         self.cc = self.find_exe("cl.exe")
         self.linker = self.find_exe("link.exe")
msg46007 - (view) Author: Connelly (connelly) Date: 2004-05-19 20:40
Logged In: YES 
user_id=1039782

BTW: You can test this out with the extension module 
myspell-python, available at:

  http://www.zgoda.biz/dnld/myspell-python-1.0-
minimal.tar.gz

Follow the directions at 
http://sebsauvage.net/python/mingw.html.  You'll encounter 
an error.  Patch msvccompiler.py and try again; now it works.
msg46008 - (view) Author: Connelly (connelly) Date: 2004-05-19 20:41
Logged In: YES 
user_id=1039782

Here's the upload.
msg46009 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-06-01 15:41
Logged In: YES 
user_id=11105

This is not a bug.  The 'install' command internally runs
the 'build' command, and this command misses the -cmingw32
flag.  Basically, you have two options to build and install
the extension:
- call 'python setup.py build -cmingw32 install'
- create/edit your distutils configuration file setup.cfg. 
Add this section (untested, but you get the idea):

[build_ext]
compiler=mingw32

See distutils docs for more details - the latter way is the
recommended one.  Does this help?
msg46010 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-03-04 14:02
Logged In: YES 
user_id=21627

With the current CVS, this problem is fixed: The install
command does not require a MSVC anymore if there is nothing
to build. Closing the patch as out-of-date.
History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40271
2004-05-19 20:37:46connellycreate