我是Cython的新手,我正试图从this project编译Cython但没有成功。
使用此setup.py,
from distutils.core import setup, Extension
from Cython.Distutils import build_ext
from distutils.extension import Extension
sources_list = ["timgraph.pyx", "Graph.cpp", "InfGraph.cpp", "sfmt/SFMT.c"]
setup(ext_modules=[Extension("pytim",
sources=sources_list,
language="c++",
extra_compile_args=["-std=c++11"])
],
cmdclass={'build_ext':build_ext})
我运行以下内容:
python setup.py build_ext --inplace
并收到以下错误:
error: invalid argument '-std=c++11' not allowed with 'C/ObjC'
error: command 'clang' failed with exit status 1
我正在运行macOS High Sierra 10.13.2,Python 3.6.2,Cython 0.27.3和Apple LLVM 9.0.0版本,如果有任何帮助的话。
编辑: 我想也许是因为尝试同时编译C和C ++,因为我可以运行Cython example for C++并且它工作正常。但我不知道如何解决extra_compile_args适用于所有来源的事实,包括“sfmt / SFMT.c”。
答案 0 :(得分:0)
在Python 3.7和3.6.5及更高版本中也遇到了相同的问题...
尝试运行时出现错误:
pip install python-crfsuite
那是从那里的setup.py文件派生的...
错误:
error: invalid argument '-std=c99' not allowed with 'C++/ObjC++'
对我来说唯一有效的方法是使用Python 3.6.4运行它
转到here安装3.6.4,然后重试。
或者在此处与Conda / Anaconda一起使用
如果您遇到在Python3.7上遇到的pkgs问题,并且有mac,请尝试使用以下方法解决它:
答案 1 :(得分:0)
就记录而言,解决方案非常简单:完全删除extra_compile_args
自变量,但仍将语言自变量设置为c++
,即
from distutils.core import setup, Extension
from Cython.Distutils import build_ext
from distutils.extension import Extension
sources_list = ["timgraph.pyx", "Graph.cpp", "InfGraph.cpp", "sfmt/SFMT.c"]
setup(ext_modules=[Extension("pytim",
sources=sources_list,
language="c++")
],
cmdclass={'build_ext':build_ext})
无论出于何种原因,这都能成功编译C和C ++。