(python study) C Module for using in python using distutils (and Unable to find vcvarsall.bat problem)

The method to make C module for using in python using Visual Studio IDE is introduced on the http://feelmare.blogspot.kr/2014/02/python-study-c-module-for-using-in.html

In this page, I will introduce to make c module using distutils.
The method to use distutils is more simple than VS version.

Firstly, we have to make setup.py file like this.

# -*- coding:  cp949 -*-
# python
# install method : setup.py install
# setup.py -help

#from distutils.core import setup, Extension
from distutils.core import setup, Extension
spam_mod = Extension('spam', sources = ['spammodule.c'])
setup (name = "spam",
      version = "1.0",
      description = "A sample extension module",
      ext_modules = [spam_mod],

type "python setup.py install" on the command line.

Note, python.exe, setup.py, spammodule.c is placed in same folder.

After running, Our .pyd (lib) is made in the python\Lib\site-packages

Now, we can import spam 

If you meet "unable to find vcvarsall.bat" error, dont be worry, 't is not serious error.
I also meet this error and solve.

The problem is occurred python find vs 9.0 version even though my computer installed vs 11. 
so correct this miss-match.

firstly, try this method 

if you cannot solve error
try this method
open python/Lib/distutils/msvc9compiler.py
and modify code like figure.

I solved this error by second method.

good luck~!!


Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

Optical Flow sample source code using OpenCV

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

SICK LMS511 sensor data acquisition interface (source code, C++/MFC)

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Image warping (using opencv findHomography, warpPerspective)