2

My directory structure

kents-air:Cython-Test kent$ tree
.
├── main.py
├── setup.py
└── test
    ├── test.c
    └── test.pyx

1 directory, 4 files

test.pyx

from libc.stdio cimport FILE

cdef class RandomTest:
    cdef File * reader
    cdef int number

    def __init__(self, number):
        self.number = number

    def print_random(self):
        print(self.number)

main.py

from .test import RandomTest

tester = RandomTest(5)
tester.print_random()

setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize(["test/*.pyx"]),
)

Output

pythkents-air:Cython-Test kent$ python3 setup.py build_ext
Compiling test/test.pyx because it changed.
[1/1] Cythonizing test/test.pyx

Error compiling Cython file:
------------------------------------------------------------
...
from libc.stdio cimport FILE

cdef class RandomTest:
    cdef File * reader
        ^
------------------------------------------------------------

test/test.pyx:4:9: 'File' is not a type identifier
Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    ext_modules = cythonize(["test/*.pyx"]),
  File "/usr/local/lib/python3.5/site-packages/Cython/Build/Dependencies.py", line 912, in cythonize
    cythonize_one(*args)
  File "/usr/local/lib/python3.5/site-packages/Cython/Build/Dependencies.py", line 1034, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: test/test.pyx

Version Info

kents-air:Cython-Test kent$ python3
Python 3.5.1 (default, Apr 18 2016, 11:46:32) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Cython==0.24

Links I have already checked:

Declaring FILE pointers in Cython Pass file handle to cython function

Community
  • 1
  • 1
Kent Shikama
  • 3,910
  • 3
  • 22
  • 55

0 Answers0