<bdo id='0xp6A'></bdo><ul id='0xp6A'></ul>

    <tfoot id='0xp6A'></tfoot>

      <small id='0xp6A'></small><noframes id='0xp6A'>

      <i id='0xp6A'><tr id='0xp6A'><dt id='0xp6A'><q id='0xp6A'><span id='0xp6A'><b id='0xp6A'><form id='0xp6A'><ins id='0xp6A'></ins><ul id='0xp6A'></ul><sub id='0xp6A'></sub></form><legend id='0xp6A'></legend><bdo id='0xp6A'><pre id='0xp6A'><center id='0xp6A'></center></pre></bdo></b><th id='0xp6A'></th></span></q></dt></tr></i><div id='0xp6A'><tfoot id='0xp6A'></tfoot><dl id='0xp6A'><fieldset id='0xp6A'></fieldset></dl></div>
      <legend id='0xp6A'><style id='0xp6A'><dir id='0xp6A'><q id='0xp6A'></q></dir></style></legend>

      1. Python distutils,如何获得将要使用的编译器?

        时间:2023-07-04
          <tbody id='vc29G'></tbody>
        <tfoot id='vc29G'></tfoot>

        • <i id='vc29G'><tr id='vc29G'><dt id='vc29G'><q id='vc29G'><span id='vc29G'><b id='vc29G'><form id='vc29G'><ins id='vc29G'></ins><ul id='vc29G'></ul><sub id='vc29G'></sub></form><legend id='vc29G'></legend><bdo id='vc29G'><pre id='vc29G'><center id='vc29G'></center></pre></bdo></b><th id='vc29G'></th></span></q></dt></tr></i><div id='vc29G'><tfoot id='vc29G'></tfoot><dl id='vc29G'><fieldset id='vc29G'></fieldset></dl></div>

              • <small id='vc29G'></small><noframes id='vc29G'>

                  <bdo id='vc29G'></bdo><ul id='vc29G'></ul>
                • <legend id='vc29G'><style id='vc29G'><dir id='vc29G'><q id='vc29G'></q></dir></style></legend>

                • 本文介绍了Python distutils,如何获得将要使用的编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  例如,我可以使用 python setup.py build --compiler=msvcpython setup.py build --compiler=mingw32 或只是 pythonsetup.py build,在这种情况下,将使用默认编译器(例如,bcpp).如何在 setup.py 中获取编译器名称(例如分别为 msvcmingw32bcpp)?

                  For example, I may use python setup.py build --compiler=msvc or python setup.py build --compiler=mingw32 or just python setup.py build, in which case the default compiler (say, bcpp) will be used. How can I get the compiler name inside my setup.py (e. g. msvc, mingw32 and bcpp, respectively)?

                  UPD.:我不需要默认编译器,我需要的是实际上将要使用的编译器,不一定是默认编译器.到目前为止,我还没有找到比解析 sys.argv 以查看是否有 --compiler... 字符串更好的方法.

                  UPD.: I don't need the default compiler, I need the one that is actually going to be used, which is not necessarily the default one. So far I haven't found a better way than to parse sys.argv to see if there's a --compiler... string there.

                  推荐答案

                  这是 Luper Rouch 答案的扩展版本,它帮助我获得了一个 openmp 扩展,以便在 Windows 上同时使用 mingw 和 msvc 进行编译.在子类化 build_ext 之后,您需要将其传递给 cmdclass arg 中的 setup.py.通过继承 build_extensions 而不是 finalize_options,您将拥有要查看的实际编译器对象,因此您可以获得更详细的版本信息.您最终可以在每个编译器、每个扩展的基础上设置编译器标志:

                  This is an expanded version of Luper Rouch's answer that worked for me to get an openmp extension to compile using both mingw and msvc on windows. After subclassing build_ext you need to pass it to setup.py in the cmdclass arg. By subclassing build_extensions instead of finalize_options you'll have the actual compiler object to look into, so you can then get more detailed version information. You could eventually set compiler flags on a per-compiler, per-extension basis:

                  from distutils.core import setup, Extension
                  from distutils.command.build_ext import build_ext
                  copt =  {'msvc': ['/openmp', '/Ox', '/fp:fast','/favor:INTEL64','/Og']  ,
                       'mingw32' : ['-fopenmp','-O3','-ffast-math','-march=native']       }
                  lopt =  {'mingw32' : ['-fopenmp'] }
                  
                  class build_ext_subclass( build_ext ):
                      def build_extensions(self):
                          c = self.compiler.compiler_type
                          if copt.has_key(c):
                             for e in self.extensions:
                                 e.extra_compile_args = copt[ c ]
                          if lopt.has_key(c):
                              for e in self.extensions:
                                  e.extra_link_args = lopt[ c ]
                          build_ext.build_extensions(self)
                  
                  mod = Extension('_wripaca',
                              sources=['../wripaca_wrap.c', 
                                       '../../src/wripaca.c'],
                              include_dirs=['../../include']
                              )
                  
                  setup (name = 'wripaca',
                     ext_modules = [mod],
                     py_modules = ["wripaca"],
                     cmdclass = {'build_ext': build_ext_subclass } )
                  

                  这篇关于Python distutils,如何获得将要使用的编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将运算符分配给python中的变量? 下一篇:如何在 Windows 7 中安装 pywin32 模块

                  相关文章

                    <small id='99iDd'></small><noframes id='99iDd'>

                  1. <legend id='99iDd'><style id='99iDd'><dir id='99iDd'><q id='99iDd'></q></dir></style></legend>

                      <i id='99iDd'><tr id='99iDd'><dt id='99iDd'><q id='99iDd'><span id='99iDd'><b id='99iDd'><form id='99iDd'><ins id='99iDd'></ins><ul id='99iDd'></ul><sub id='99iDd'></sub></form><legend id='99iDd'></legend><bdo id='99iDd'><pre id='99iDd'><center id='99iDd'></center></pre></bdo></b><th id='99iDd'></th></span></q></dt></tr></i><div id='99iDd'><tfoot id='99iDd'></tfoot><dl id='99iDd'><fieldset id='99iDd'></fieldset></dl></div>

                        <bdo id='99iDd'></bdo><ul id='99iDd'></ul>
                    1. <tfoot id='99iDd'></tfoot>