首页 > 解决方案 > 在 nogil 中使用 dict

问题描述

我想在 nogil 中使用字典。我已经阅读了这个问题和@DavidW 的评论:

Cythonize python 字典对象

所以我尝试在 file.pyx 中这样做:

# cython: language_level=3
cimport cpython.dict
cdef cpython.dict some_cdict

我的 setup.py 文件如下所示:

from setuptools import setup
from Cython.Build import cythonize
import numpy as np

setup(
    ext_modules=cythonize('file.pyx', annotate=True),
    include_dirs=[np.get_include()]
)

这是我编译它的调用:

python setup.py build_ext --inplace

但我得到这个错误:

file.pyx:3:5: 'dict' is not a type identifier

我究竟做错了什么?

我也看到了这个解决方案,但我更愿意使用 CPython 中的对象而不是 libcpp:

https://stackoverflow.com/a/32267243/1884520

标签: dictionarycython

解决方案


推荐阅读