I used cython for the first time. I stumbled on various things just by moving a simple module, so I will leave it as a memo.
Environment: Mac OS El Capitan
I referred to Learning Cython Programming --Second Edition. The code is here.
In the book, I made a .pyx
file, but I tried using a normal .py
file.
cython -o helloworld.c helloworld.py
Then compile.
gcc -g -O2 -fpic -c helloworld.c -o helloworld.o `python-config --cflags`
gcc -g -O2 -shared -o helloworld.so helloworld.o `python-config --libs`
When I imported the .so
file created in this way, a segmentation fault occurred.
An issue was reported on github for this issue, and I changed the options passed to gcc and the error did not occur.
gcc -g -O2 -fpic -c helloworld.c -o helloworld.o `python-config --cflags`
gcc -g -O2 -shared -o helloworld.so helloworld.o `python-config --ldflags`
Also, in cython documentation, distutils The procedure for using is described, and I thought it was easier.
Symbol not found: _PyUnicodeUCS4_Compare
Now that the practice is over, I built the module I'm targeting with cython. When I tried using it, I got an ImportError error called Symbol not found: _PyUnicodeUCS4_Compare.
Refer to this article, remove python 2.7.12 installed with virtualenv, and try running it with python on the Mac system. I did.
Is it a matter of which module to link with at build time? Unlike plain python, cython is troublesome.
Recommended Posts