可以更改distutils默认的编译器选项吗?

时间:2019-01-22 11:41:20

标签: python mingw distutils mingw-w64 mingw32

Win 10,x64,minGW64,Python 2.7,Anaconda

我正在尝试使用python setup.py build --compiler=mingw32

编译zbar以在Python 2.7中使用

这是setup.py

from distutils.core import setup, Extension
from distutils.sysconfig import get_config_vars
setup(
    name = 'zbar',
    version = '0.10',
    author = 'Jeff Brown',
    author_email = 'spadix@users.sourceforge.net',
    url = 'http://zbar.sourceforge.net',
    description = 'read barcodes from images or video',
    license = 'LGPL',
    long_description = open('README').read(),
    classifiers = [
        'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
        'Development Status :: 4 - Beta',
        'Intended Audience :: Developers',
        'Environment :: Console',
        'Environment :: X11 Applications',
        'Environment :: Win32 (MS Windows)',
        'Operating System :: POSIX',
        'Operating System :: Unix',
        'Operating System :: Microsoft :: Windows',
        'Topic :: Communications',
        'Topic :: Multimedia :: Graphics',
        'Topic :: Software Development :: Libraries',
    ],
    ext_modules = [
        Extension('zbar', [
                'zbarmodule.c',
                'enum.c',
                'exception.c',
                'symbol.c',
                'symbolset.c',
                'symboliter.c',
                'image.c',
                'processor.c',
                'imagescanner.c',
                'decoder.c',
                'scanner.c',
                ],
            libraries = [ 'zbar' ],
            library_dirs=["""C:\Program Files (x86)\ZBar\lib"""],
            include_dirs=[get_config_vars('INCLUDEDIR'),
                              get_config_vars('INCLUDEPY'),
                             """C:\Program Files (x86)\ZBar\include"""]
        ),
    ],
)

但是我不断收到以下错误信息……

running build
running build_ext
building 'zbar' extension
C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\gcc.exe -mno-cygwin -mdll -O -Wall -DMS_WIN64 -I[None] -I['C:\\ProgramData\\Anaconda2\\include'] "-IC:\Program Files (x86)\ZBar\include" -IC:\ProgramData\Anaconda2\include -IC:\ProgramData\Anaconda2\PC -c zbarmodule.c -o build\temp.win-amd64-2.7\Release\zbarmodule.o
gcc: error: unrecognized command line option '-mno-cygwin'; did you mean '-mno-clwb'?
error: command 'C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe' failed with exit status 1

从此post看来,'-mno-cywin'不再是有效的编译选项,因此会出现错误。

我发现this post关于Mac OS X 10.8.3的distutils编译器选项,并发现某个地方distutils从原始Python安装中读取了一些默认标志,但我不是明智地更改它们。

如何在Windows 10计算机上通过Python的Anaconda发行版(即缺少distutils的情况下)更改传递给disutils.cfg的编译器选项?

是否可以编写自己的distutils.cfg

1 个答案:

答案 0 :(得分:1)

该选项位于distutils/cygwinccompiler.py中。如果您可以在Python安装中编辑文件,请­将其删除。