如何在setup.py中设置编译器选项。

huangapple go评论54阅读模式
英文:

How to set the compiler options in setup.py

问题

以下是翻译好的内容:

我正在尝试编译一个简单的 test.pyx 文件。为此,我创建了以下 setup.py 文件:

from setuptools import setup
from Cython.Build import cythonize

setup(
    compiler_directives={'language_level': '3'},
    extra_compile_args=['-Ofast', '-march=native'],
    ext_modules=cythonize("test.pyx")
)

我收到了以下警告:

UserWarning: Unknown distribution option: 'compiler_directives'
  warnings.warn(msg)
Unknown distribution option: 'extra_compile_args'
  warnings.warn(msg)

我应该如何正确操作?

我正在使用 Cython 版本 0.29.35。

英文:

I am trying to compile a simple test.pyx file. To do this I made setup.py as follows:

from setuptools import setup
from Cython.Build import cythonize

setup(
    compiler_directives={'language_level' : "3"},
    extra_compile_args=['-Ofast', '-march=native'],
    ext_modules = cythonize("test.pyx")
)

I get the warnings:

UserWarning: Unknown distribution option: 'compiler_directives'
  warnings.warn(msg)
Unknown distribution option: 'extra_compile_args'
  warnings.warn(msg)

How should I have done this?

I am using Cython version 0.29.35 .

答案1

得分: 1

Thanks to Marijn this compiles without warnings:

from setuptools import setup
from Cython.Build import cythonize
from setuptools.extension import Extension

ext_modules = [
    Extension(
        'test_sum',
        language='c',
        sources=['test.pyx'],  # list of source files
        extra_compile_args=['-Ofast', '-march=native'],  # example extra compiler arguments
    )
]

setup(
    name="test module",
    ext_modules=cythonize(ext_modules, compiler_directives={'language_level': "3"})
)

如果您需要进一步的帮助,请随时提问。

英文:

Thanks to Marijn this compiles without warnings:

from setuptools import setup
from Cython.Build import cythonize
from setuptools.extension import Extension

ext_modules = [
    Extension(
        'test_sum',
        language='c',
        sources=['test.pyx'],  # list of source files
        extra_compile_args=['-Ofast', '-march=native'],  # example extra compiler arguments
    )
]

setup(
    name = "test module",
    ext_modules = cythonize(ext_modules, compiler_directives={'language_level' : "3"})
    
)

huangapple
  • 本文由 发表于 2023年5月31日 23:58:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375361.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定