Python distutils build problems with MinGW

Discussion in 'Python' started by Andrej Mitrovic, Feb 1, 2010.

  1. Hi,

    I've made a similar post on the Cython mailing list, however I think
    this is more python-specific. I'm having trouble setting up distutils
    to use MinGW instead of Visual Studio when building a module. Even tho
    I've just uninstalled VS, and cleared out any leftover VS environment
    variables, distutils keeps wanting to use it.

    The steps I took:

    Fresh installation of Python 3.1.1
    Successfully installed MinGW, added to the path variable (gcc in
    command prompt works)
    Successfully installed Cython, imports from Cython in Python work.
    Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:

    [build]
    compiler=mingw32

    (also tried adding [build_ext] compiler=mingw32)

    There's a demo setup.py module that came with Cython, I tried the
    following commands:

    ----------------------------------------------------
    > python setup.py build_ext --inplace


    error: Unable to find vcvarsall.bat

    > python setup.py build


    error: Unable to find vcvarsall.bat
    ----------------------------------------------------

    I'm having the exact same issue with trying to build the Polygon
    library via MinGW. In fact, the reason I had installed Visual Studio
    in the first place was to be able to build the Polygon library, since
    I was having these errors.

    What do I need to do to make distutils/python use MinGW?
    Andrej Mitrovic, Feb 1, 2010
    #1
    1. Advertising

  2. On Feb 1, 2:59 am, Andrej Mitrovic <> wrote:
    > Hi,
    >
    > I've made a similar post on the Cython mailing list, however I think
    > this is more python-specific. I'm having trouble setting up distutils
    > to use MinGW instead of Visual Studio when building a module. Even tho
    > I've just uninstalled VS, and cleared out any leftover VS environment
    > variables, distutils keeps wanting to use it.
    >
    > The steps I took:
    >
    > Fresh installation of Python 3.1.1
    > Successfully installed MinGW, added to the path variable (gcc in
    > command prompt works)
    > Successfully installed Cython, imports from Cython in Python work.
    > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:
    >
    > [build]
    > compiler=mingw32
    >
    > (also tried adding [build_ext] compiler=mingw32)
    >
    > There's a demo setup.py module that came with Cython, I tried the
    > following commands:
    >
    > ----------------------------------------------------
    >
    > > python setup.py build_ext --inplace

    >
    > error: Unable to find vcvarsall.bat
    >
    > > python setup.py build

    >
    > error: Unable to find vcvarsall.bat
    > ----------------------------------------------------
    >
    > I'm having the exact same issue with trying to build the Polygon
    > library via MinGW. In fact, the reason I had installed Visual Studio
    > in the first place was to be able to build the Polygon library, since
    > I was having these errors.
    >
    > What do I need to do to make distutils/python use MinGW?


    Update:

    I installed and tried building with Python 2.6, it calls MinGW when I
    have the distutils.cfg file configured properly (same configuration as
    the Python 3.1.1 one)

    But why doesn't it work on a fresh Python 3.1.1 installation as well?
    Is this a bug?
    Andrej Mitrovic, Feb 1, 2010
    #2
    1. Advertising

  3. On Feb 1, 4:03 am, Andrej Mitrovic <> wrote:
    > On Feb 1, 2:59 am, Andrej Mitrovic <> wrote:
    >
    >
    >
    > > Hi,

    >
    > > I've made a similar post on the Cython mailing list, however I think
    > > this is more python-specific. I'm having trouble setting up distutils
    > > to use MinGW instead of Visual Studio when building a module. Even tho
    > > I've just uninstalled VS, and cleared out any leftover VS environment
    > > variables, distutils keeps wanting to use it.

    >
    > > The steps I took:

    >
    > > Fresh installation of Python 3.1.1
    > > Successfully installed MinGW, added to the path variable (gcc in
    > > command prompt works)
    > > Successfully installed Cython, imports from Cython in Python work.
    > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:

    >
    > > [build]
    > > compiler=mingw32

    >
    > > (also tried adding [build_ext] compiler=mingw32)

    >
    > > There's a demo setup.py module that came with Cython, I tried the
    > > following commands:

    >
    > > ----------------------------------------------------

    >
    > > > python setup.py build_ext --inplace

    >
    > > error: Unable to find vcvarsall.bat

    >
    > > > python setup.py build

    >
    > > error: Unable to find vcvarsall.bat
    > > ----------------------------------------------------

    >
    > > I'm having the exact same issue with trying to build the Polygon
    > > library via MinGW. In fact, the reason I had installed Visual Studio
    > > in the first place was to be able to build the Polygon library, since
    > > I was having these errors.

    >
    > > What do I need to do to make distutils/python use MinGW?

    >
    > Update:
    >
    > I installed and tried building with Python 2.6, it calls MinGW when I
    > have the distutils.cfg file configured properly (same configuration as
    > the Python 3.1.1 one)
    >
    > But why doesn't it work on a fresh Python 3.1.1 installation as well?
    > Is this a bug?


    Also tried calling (Python 3.1.1):

    ----------------------------------------------------
    python setup.py build --compiler=mingw32

    error: Unable to find vcvarsall.bat
    ----------------------------------------------------

    I've tried using pexports and the dlltool to build new python31.def
    and libpython31.a files, and put them in the libs folder. That didn't
    work either.

    I've also tried adding some print statements in the \distutils\dist.py
    file, in the parse_config_files() function, just to see if Python
    properly parses the config file. And it does, both Python 2.6 and 3.1
    parse the distutils.cfg file properly. Yet something is making python
    3 look for the VS/VC compiler instead of MinGW. I'll keep updating on
    any progres..
    Andrej Mitrovic, Feb 1, 2010
    #3
  4. Andrej Mitrovic

    casevh Guest

    On Feb 1, 8:31 am, Andrej Mitrovic <> wrote:
    > On Feb 1, 4:03 am, Andrej Mitrovic <> wrote:
    >
    >
    >
    >
    >
    > > On Feb 1, 2:59 am, Andrej Mitrovic <> wrote:

    >
    > > > Hi,

    >
    > > > I've made a similar post on the Cython mailing list, however I think
    > > > this is more python-specific. I'm having trouble setting up distutils
    > > > to use MinGW instead of Visual Studio when building a module. Even tho
    > > > I've just uninstalled VS, and cleared out any leftover VS environment
    > > > variables, distutils keeps wanting to use it.

    >
    > > > The steps I took:

    >
    > > > Fresh installation of Python 3.1.1
    > > > Successfully installed MinGW, added to the path variable (gcc in
    > > > command prompt works)
    > > > Successfully installed Cython, imports from Cython in Python work.
    > > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:

    >
    > > > [build]
    > > > compiler=mingw32

    >
    > > > (also tried adding [build_ext] compiler=mingw32)

    >
    > > > There's a demo setup.py module that came with Cython, I tried the
    > > > following commands:

    >
    > > > ----------------------------------------------------

    >
    > > > > python setup.py build_ext --inplace

    >
    > > > error: Unable to find vcvarsall.bat

    >
    > > > > python setup.py build

    >
    > > > error: Unable to find vcvarsall.bat
    > > > ----------------------------------------------------

    >
    > > > I'm having the exact same issue with trying to build the Polygon
    > > > library via MinGW. In fact, the reason I had installed Visual Studio
    > > > in the first place was to be able to build the Polygon library, since
    > > > I was having these errors.

    >
    > > > What do I need to do to make distutils/python use MinGW?

    >
    > > Update:

    >
    > > I installed and tried building with Python 2.6, it calls MinGW when I
    > > have the distutils.cfg file configured properly (same configuration as
    > > the Python 3.1.1 one)

    >
    > > But why doesn't it work on a fresh Python 3.1.1 installation as well?
    > > Is this a bug?

    >
    > Also tried calling (Python 3.1.1):
    >
    > ----------------------------------------------------
    > python setup.py build --compiler=mingw32
    >
    > error: Unable to find vcvarsall.bat
    > ----------------------------------------------------
    >
    > I've tried using pexports and the dlltool to build new python31.def
    > and libpython31.a files, and put them in the libs folder. That didn't
    > work either.
    >
    > I've also tried adding some print statements in the \distutils\dist.py
    > file, in the parse_config_files() function, just to see if Python
    > properly parses the config file. And it does, both Python 2.6 and 3.1
    > parse the distutils.cfg file properly. Yet something is making python
    > 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on
    > any progres..- Hide quoted text -
    >
    > - Show quoted text -


    I think this is http://bugs.python.org/issue6377.

    I applied the patch to my local copy of Python 3.1 and it seems to
    work.

    casevh
    casevh, Feb 1, 2010
    #4
  5. I've found the problem:

    For the windows Python 3.1.1 x86 installation, the file \Python31\Lib
    \Distutils\command\build_ext.py, has this:

    Line 313:

    self.compiler = new_compiler(compiler=None,

    But Python 2.6 has this line:

    Line 306:

    self.compiler = new_compiler(compiler=self.compiler,



    I've changed the Python 3.1.1 \Python31\Lib\Distutils\command
    \build_ext.py, Line 313 to this:

    self.compiler = new_compiler(compiler=self.compiler,

    And now MinGW gets properly called in Python 3.1.1. I think this must
    have been a typo.


    Is there anyone else that can confirm this?

    The installation that distributes the file with that line is from this
    Python ftp link: http://python.org/ftp/python/3.1.1/python-3.1.1.msi
    Andrej Mitrovic, Feb 1, 2010
    #5
  6. On Feb 1, 5:44 pm, casevh <> wrote:
    > On Feb 1, 8:31 am, Andrej Mitrovic <> wrote:
    >
    >
    >
    > > On Feb 1, 4:03 am, Andrej Mitrovic <> wrote:

    >
    > > > On Feb 1, 2:59 am, Andrej Mitrovic <> wrote:

    >
    > > > > Hi,

    >
    > > > > I've made a similar post on the Cython mailing list, however I think
    > > > > this is more python-specific. I'm having trouble setting up distutils
    > > > > to use MinGW instead of Visual Studio when building a module. Even tho
    > > > > I've just uninstalled VS, and cleared out any leftover VS environment
    > > > > variables, distutils keeps wanting to use it.

    >
    > > > > The steps I took:

    >
    > > > > Fresh installation of Python 3.1.1
    > > > > Successfully installed MinGW, added to the path variable (gcc in
    > > > > command prompt works)
    > > > > Successfully installed Cython, imports from Cython in Python work.
    > > > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with:

    >
    > > > > [build]
    > > > > compiler=mingw32

    >
    > > > > (also tried adding [build_ext] compiler=mingw32)

    >
    > > > > There's a demo setup.py module that came with Cython, I tried the
    > > > > following commands:

    >
    > > > > ----------------------------------------------------

    >
    > > > > > python setup.py build_ext --inplace

    >
    > > > > error: Unable to find vcvarsall.bat

    >
    > > > > > python setup.py build

    >
    > > > > error: Unable to find vcvarsall.bat
    > > > > ----------------------------------------------------

    >
    > > > > I'm having the exact same issue with trying to build the Polygon
    > > > > library via MinGW. In fact, the reason I had installed Visual Studio
    > > > > in the first place was to be able to build the Polygon library, since
    > > > > I was having these errors.

    >
    > > > > What do I need to do to make distutils/python use MinGW?

    >
    > > > Update:

    >
    > > > I installed and tried building with Python 2.6, it calls MinGW when I
    > > > have the distutils.cfg file configured properly (same configuration as
    > > > the Python 3.1.1 one)

    >
    > > > But why doesn't it work on a fresh Python 3.1.1 installation as well?
    > > > Is this a bug?

    >
    > > Also tried calling (Python 3.1.1):

    >
    > > ----------------------------------------------------
    > > python setup.py build --compiler=mingw32

    >
    > > error: Unable to find vcvarsall.bat
    > > ----------------------------------------------------

    >
    > > I've tried using pexports and the dlltool to build new python31.def
    > > and libpython31.a files, and put them in the libs folder. That didn't
    > > work either.

    >
    > > I've also tried adding some print statements in the \distutils\dist.py
    > > file, in the parse_config_files() function, just to see if Python
    > > properly parses the config file. And it does, both Python 2.6 and 3.1
    > > parse the distutils.cfg file properly. Yet something is making python
    > > 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on
    > > any progres..- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > I think this ishttp://bugs.python.org/issue6377.
    >
    > I applied the patch to my local copy of Python 3.1 and it seems to
    > work.
    >
    > casevh


    Thanks for the link, it seems like it's got more to do than what I
    just posted. But in any case, it works for me now.

    I think I'll have to open myself a blog and post some guides for
    problems like these, so people can avoid spending whole nights around
    a problem like this. :)
    Andrej Mitrovic, Feb 1, 2010
    #6
  7. Well, in any case this seems to be working ok for me now.
    Andrej Mitrovic, Feb 1, 2010
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam Smith
    Replies:
    0
    Views:
    1,161
    Sam Smith
    Oct 18, 2004
  2. Andrew Gregory

    Python 2.3 distutils with Mingw C++

    Andrew Gregory, Jul 30, 2003, in forum: Python
    Replies:
    0
    Views:
    358
    Andrew Gregory
    Jul 30, 2003
  3. Uwe Schmitt

    build python using mingw

    Uwe Schmitt, Sep 17, 2003, in forum: Python
    Replies:
    2
    Views:
    407
    John J. Lee
    Sep 18, 2003
  4. xeno fears
    Replies:
    1
    Views:
    493
    Martin v. Löwis
    Oct 4, 2009
  5. Kaspar Schiess
    Replies:
    0
    Views:
    119
    Kaspar Schiess
    Jul 7, 2004
Loading...

Share This Page