首页 > 解决方案 > 使用 Jupyter Notebook 在 Cython 中的 unordered_set

问题描述

我一直试图在我的 Mac 上的 Jupyter Notebook 中使用 Cython 中的 unordered_sets。

%%cython -a -3
# distutils: language = c++
# cython: c_string_type=unicode, c_string_encoding=utf8
import cython
from libcpp.unordered_set cimport unordered_set

def test():
    cdef unordered_set[int] s
    return s

上面的单元格抛出: DistutilsExecError: command 'gcc' failed with exit status 1

标签: pythonjupyter-notebookcython

解决方案


Older gcc versions don't use c++-11 (but c++-98) per default, and because unordered_map is a c++11-feature, you need to pass the option to the compiler.

For example via:

%%cython -a -3 -c=-std=c++11

Or update your gcc to 6.0 or above.


推荐阅读