可以用icc编译cython吗?

时间:2016-06-19 05:53:15

标签: python-3.x ubuntu-14.04 cython distutils icc

我正在尝试使用icc编译器在Ubuntu 14.04上从源代码构建cython,因为我的python是用Intel icc编译器编译的。

当我尝试使用 pip3安装cython 安装cython然后运行cython时出现以下错误

Traceback (most recent call last):
File "/usr/local/bin/cython", line 9, in <module>
load_entry_point('Cython==0.24', 'console_scripts', 'cython')()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 351, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2363, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2088, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/local/lib/python3.4/dist-packages/Cython/Compiler/Main.py", line 28, in <module>
from .Scanning import PyrexScanner, FileSourceDescriptor
ImportError: /usr/local/lib/python3.4/dist-packages/Cython/Compiler/Scanning.cpython-34m.so: undefined symbol: __intel_sse2_strchr 

如何使用icc编译器从源代码安装cython?

我尝试了这个并且它不起作用

从cython目录(从github下载)

python3.4 setup.py CC = icc

我收到以下消息 -

/home/aa/libPython/cython/Cython/Distutils/build_ext.py:20: UserWarning:    
Cython.Distutils.build_ext does not properly handle dependencies and is deprectated. Use Cython.Build.build_ext instead.
"Cython.Distutils.build_ext does not properly handle dependencies "
 Unable to find pgen, not compiling formal grammar.
 invalid command name 'CC=icc'

1 个答案:

答案 0 :(得分:5)

CC=icc不足以使用icc构建。您还应该链接icc(https://stackoverflow.com/a/10891764/196561; icc将其内部库添加到ELF文件中),因此找到setup.py的链接器变量名称,可能是LD并将其设置为icc too {{ 1}}(默认可能是gcc)。

实际上是LD=icc - https://github.com/cython/cython/blob/970c2fc0e676ca22016e14147ada0edba937dc6b/Cython/Build/BuildExecutable.py

LINKCC

因此,使用icc对cython的正确构建应该是CC = get_config_var('CC', os.environ.get('CC', '')) CFLAGS = get_config_var('CFLAGS') + ' ' + os.environ.get('CFLAGS', '') LINKCC = get_config_var('LINKCC', os.environ.get('LINKCC', CC)) ,不知道应该如何将变量传递到setup.py,检查How to tell distutils to use gcc?或尝试

CC=icc LINKCC=icc

更新:根据gansub的消息,“CC=icc LINKCC=icc python3.4 setup.py ”env。变量将有助于构建cython:“你需要设置环境变量LDSHARED = icc” - http://chat.stackoverflow.com/transcript/message/31231907#31231907https://stackoverflow.com/a/37914227

来自Syrtis Major的更新:2016年12月15日,Nguyen,Loc Q(英特尔)发表文章“Cython *中的线程并行”https://software.intel.com/en-us/articles/thread-parallelism-in-cython,建议 LDSHARED=icc

  

要显式使用Intel icc编译此应用程序,请使用以下命令执行setup.py文件:

LDSHARED="icc -shared" CC=icc