python distutils尝试设置

时间:2016-06-03 14:57:50

标签: python-2.7 cython distutils

我正在尝试使用distutils.core.setup编译一些cython代码文件 为了防止编译崩溃但要尽可能地继续,我将每个文件扩展名放在try语句中

from distutils.core import setup, Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import numpy as np

pyx = [#file 1
       Extension('file1',
       include_dirs=[np.get_include()],
       sources ["file1.pyx"]),

       #file 2
       Extension('file2',
       include_dirs=[np.get_include()],
       language="c",
       sources = ["file2.pyx"]),

       #rest of files
       ]

       # compile extensions
       for E in pyx :
           try:
               setup( ext_modules = [E], cmdclass={'build_ext': build_ext})
           except Exception as e:
               print "THIS IS AN ERROR", e

一切正常,除非出现错误,尝试捕捉似乎没用。编译将停止,不经过语句。

知道为什么以及该怎么做?

1 个答案:

答案 0 :(得分:0)

SystemExit必须包含在

# compile extensions
for E in pyx :
    try:
        setup( ext_modules = [E], cmdclass={'build_ext': build_ext})
    except (Exception, SystemExit) as e:
        print "THIS IS AN ERROR", e