Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python C API version mismatch for module

cpp-module code:

#include <iostream>
#include <boost/python.hpp>

void Hello()
{
    std::cout << "string: " << PYTHON_API_STRING << "\n";
    std::cout << "int: " << PYTHON_API_VERSION << "\n";
}

BOOST_PYTHON_MODULE(hello)
{
    namespace py = boost::python;
    py::def("Hello", &Hello);
}

compile:

g++ -m32 -Wall -fPIC -I /usr/include -I /usr/include/python2.5/ hello.cpp -L /usr/lib/python2.5/ -Wl,-Bstatic -lboost_python -Wl,-Bdynamic -lgcc -shared -o hello.so

python console (on the same host or other - no difference):

>>> import hello
__main__:1: RuntimeWarning: Python C API version mismatch for module hello: This Python has API version 1013, module hello has version 1012.
>>> hello.Hello()
string: 1013
int: 1013
>>>

Why 1012? Where from?

like image 537
user694989 Avatar asked Mar 09 '26 16:03

user694989


1 Answers

Python's API version number is changed when there are incompatible changes to some of the internal API calls. Python 2.4 uses a version number of 1012. Python 2.5 and later use version 1013.

You appear to be including Python 2.5 so you should get a version of 1013. The API version is defined in Include/modsupport.h. Is that file corrupt or has it been modified? Does something else override the value?

like image 170
casevh Avatar answered Mar 12 '26 06:03

casevh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!