Compile cython code with “python compile.py” and no “build” command-line parameter

谁说我不能喝 提交于 2019-12-08 19:31:28
  • Method #1:

    Use script_args like this:

    setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build'])
    

    or

    setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build_ext'])
    

    (both work).

    If you want the output files to be in the same directory, you can use:

    setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build'], 
                                                options={'build':{'build_lib':'.'}})
    

    or

    setup(ext_modules=cythonize("module1.pyx", build_dir="build"), script_args=['build_ext'],
                                                options={'build_ext':{'inplace':True}})
    
  • Method #2:

    Add this on top:

     import sys; sys.argv = ["", "build"]
    

    It's a bit hack-ish but it works fine, and avoids to have to create a new build-system, like with Build and run with arguments in Sublime Text 2 (link kindly provided by @Melvin).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!