cythonbook / examples Goto Github PK
View Code? Open in Web Editor NEWCode examples from the book.
Code examples from the book.
I am in Linux Mint 18 (base on Ubuntu 16.04), and I try the code in Page 27 which is
gcc $(python-config --cflags) $(python-config --ldflags) ./irrationals.c
gcc raise dozens of error like Undefined reference to ‘Py_Initialize’
, when I change code to
gcc $(python-config --cflags) ./irrationals.c $(python-config --ldflags)
Everything works well. So is it a version specific bug?
Python v 2.7.12
Cython v 0.24.1
gcc v 5.4.0 (20160609)
When timing the Python/C API extension example in 01-essentials/03-timings/
, I got an error like this
ImportError: dlopen( ./examples/01-essentials/03-timings/cfib.cpython-36m-darwin.so, 2): Symbol not found: _Py_InitModule
Referenced from: ./examples/01-essentials/03-timings/cfib.cpython-36m-darwin.so
Expected in: flat namespace
in ./examples/01-essentials/03-timings/cfib.cpython-36m-darwin.so
The error is from line 14 in 01-essentials/03-timings/timings.py
cexttime_0 = timer(0, N, name='fib', module='cfib')
I found that Python 3.x no longer uses Py_InitModule
. So this part would not work.
Here's my attempt to fix the 01-essentials/03-timings/cfib_wrap.c
for Python 3.x.
The original PyMODINIT_FUNC
block
PyMODINIT_FUNC
initcfib(void)
{
(void) Py_InitModule("cfib", funcs);
}
can be replaced with
static struct PyModuleDef fib =
{
PyModuleDef_HEAD_INIT,
"fib",
"",
-1,
funcs
};
PyMODINIT_FUNC PyInit_cfib(void) {
return PyModule_Create(&fib);
}
This should make the example 01-essentials/03-timings
to run in Python 3.x.
Where are they? I really need them.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.