Friday, June 5, 2009

[solved] error: Setup script exited with error: Python was built with Visual Studio 2003

If you have used Python for some time on Windows you definitely bumped into this error message when installing some new modules:

error: Setup script exited with error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing "-c mingw32" to

But there are four easy steps to get through this hurdle.

1. Get and install MinGW from (
I installed the stable version into the default directory.

2. Add c:\mingw\bin to your PATH environment variable.

3. Put these lines into \lib\distutils\distutils.cfg:

compiler = mingw32

compiler = mingw32
4. Copy c:\windows\system32\python25.dll into c:\mingw\lib

Otherwise you would get:
c:\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lpython25
collect2: ld returned 1 exit status
error: Setup script exited with error: command 'gcc' failed with exit status 1

If you are using virtualenv you have to do the step 2 for all of your python virtual environments.

And you are done. This is my setup and it's sufficient to install source distributions of setuptools, cx_Oracle, simplejson, mercurial and probably other libraries. I was able to use it on Windows Vista and 2003 Server with both Python 2.5 a and Python 2.6.

Tuesday, June 2, 2009

Deploying python web application on Windows

There are many deployment scenarios with Python web applications. Without diving into all the options I'll suppose part of your deployment is utilizing Paste Deployment ( . To test and develop your application you use "paster serve some_name.ini". Now to setup the application so that it runs after log off or restart you need a customized Windows service.

There are a couple of recipes around to achieve this but, you have to copy and paste some code and hardcode the name and config file into it. I've put together a little tool which helps creating windows services, based on arbitrary configuration parameters.

First, install the tool:

easy_install WsgiWinService

This adds the wsgisvc.exe into your scripts directory.

Second, you have to extend your *.ini file with a [winservice] section. The list of options you can use:

Only the svc_name option is mandatory. If you don't use svc_display_name or svc_decription sensible default will be made up. The minimal configuration you need to add looks like this:

svc_name = svc1

Third, install the service:

wsgisvc -c some_name.ini install

This adds the service "svc1" to your system. You can check it out under display name "svc1 Paste Service" through Administrative Tools -> Services. To start the service you can either use that or command line:

wsgisvc -c some_name.ini start

And the last thing, to list display names of all installed Paste services:

wsgisvc list

If this helps somebody, let me know please.