Git Product home page Git Product logo

examples's Issues

A problem found in compile standalone excutable

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)

Example 3 in Chapter 1 does not work in Python 3.x?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.