sanya84
@sanya84
Фанатик Python 3

Как импортировать библиотеку string в Cython?

Всем привет!

Есть такой файл pyx

cdef extern from "Person.h" namespace "person":
    cdef cppclass CppPerson:
        CppPerson() except +
        CppPerson(string name, int age) except +


cdef class Person:
    cdef CppPerson *cpp_person

    def __cinit__(self):
        self.cpp_person = new CppPerson()
        if self.cpp_person == NULL:
            raise MemoryError('Not enough memory.')

    def __dealloc__(self):
        del self.cpp_person


В 4 строчке мне надо использовать тип данных string
Как его добавить?
Как сделать импорт?

Пока вот такая ошибка
C:\PyScripterProjects\Расширения для Python3 на C++\Person2>py setup.py build_ex
t --inplace
Compiling person_module.pyx because it changed.
[1/1] Cythonizing person_module.pyx
C:\Python37\lib\site-packages\Cython\Compiler\Main.py:367: FutureWarning: Cython
 directive 'language_level' not set, using 2 for now (Py2). This will change in
a later release! File: C:\PyScripterProjects\Расширения для Python3 на C++\Perso
n2\person_module.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
cdef extern from "Person.h" namespace "person":
    cdef cppclass CppPerson:
        CppPerson() except +
        CppPerson(string name, int age) except +
                 ^
------------------------------------------------------------

person_module.pyx:4:18: 'string' is not a type identifier
Traceback (most recent call last):
  File "setup.py", line 8, in <module>
    language="c++",                                  # generate and compile C++
code
  File "C:\Python37\lib\site-packages\Cython\Build\Dependencies.py", line 1097,
in cythonize
    cythonize_one(*args)
  File "C:\Python37\lib\site-packages\Cython\Build\Dependencies.py", line 1220,
in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: person_module.pyx

C:\PyScripterProjects\Расширения для Python3 на C++\Person2>
  • Вопрос задан
  • 121 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы