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 setup.py.

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

1. Get and install MinGW from (http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=240780)
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:

[build]
compiler = mingw32

[config]
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.

11 comments:

  1. Hello,

    Please can you explain what you mean by "Add c:\mingw\bin to your path.", perhaps with an example.

    Apologies, I am new to this!

    Regards,

    ReplyDelete
  2. Just to update, I have the following in a .bat file:

    C:\Python25\Scripts\easy_install.exe greenlet

    I have also tried..

    C:\Python25\Scripts\easy_install.exe;c:\mingw\bin greenlet

    Thanks for any help on this!

    ReplyDelete
  3. step 2. means modify your PATH environment variable to also include "c:\mingw\bin". Quick Google search reveals this description of what that means: http://vlaurie.com/computers2/Articles/environment.htm
    for Windows XP. If you have Vista try to Google something up pls.

    I'm improving the wording of that step..

    ReplyDelete
  4. Just a quick refresh: The guide still works for the newest Python (2.6.5) and Windows 7.

    ReplyDelete
  5. Put these lines into \lib\distutils\distutils.cfg

    I am afraid I don't have such a structure - not able to find the configuration file at C:\Python26 ?

    ReplyDelete
  6. I thought there is pythonxyz\lib\distutils directory in every windows python installation. Eg C:\Python2.6\lib\distutils.

    If no distutils.cfg file exists in the directory, you have to create it. Does it answer your question?

    ReplyDelete
  7. Hi Im trying to do this with Python 27 on Windows 7 but still getting the "collect2: ld returned 1 exit status error: Setup script exited with error: command 'gcc' failed with exit status 1" error. Can you help me?

    ReplyDelete
  8. @Anonymous: don't know if it will help, but I am getting a similar error (Windows 7/Python 2.6)
    C:\Users\mchance\Library\dulwich>python setup.py install
    running install
    running build
    running build_py
    running build_ext
    building 'dulwich._objects' extension
    c:\Applications\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Idulwich -IC:\Appl
    ications\Python26\include -IC:\Applications\Python26\PC -c dulwich/_objects.c -o
    build\temp.win32-2.6\Release\dulwich\_objects.o
    cc1.exe: error: unrecognized command line option '-mno-cygwin'
    error: command 'gcc' failed with exit status 1

    Obviously in this case it is the -m option making it fail... why that is I don't know.

    Also, FYI, for me the distutils.cfg I had to create in \Applications\Python26\Lib\distutils

    ReplyDelete
  9. PIL

    C:\Users\lk\Downloads\Compressed\PIL-1.1.7>python setup.py install
    running install
    running build
    running build_py
    running build_ext
    building '_imaging' extension
    C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IlibImaging -IC:\Python27\include -IC:\Python27\include -IC:\Python27\PC -c _imaging.c -o build\temp.win-amd64-2.7\Release\_imaging.o
    gcc: error: unrecognized command line option '-mno-cygwin'
    error: command 'gcc' failed with exit status 1

    ReplyDelete
  10. Hi,

    I found a solution for this problem.

    http://stackoverflow.com/questions/6034390/compiling-with-cython-and-mingw-produces-gcc-error-unrecognized-command-line-o

    ReplyDelete
  11. That’s a Awesome blog ,We can provide a best services of you problem , any time you can call my help desk number and solve your problem just go through this url.
    error 1068 windows7
    Thank you
    Aalia lyon

    ReplyDelete