I followed the tutorial up on the wiki http://qt-project.org/wiki/PySide_Binding_Generation_Tutorial but I can't get it to work properly. I'm on MacOSX
So far here's what I did:
- Build FooLib (static) ---> libFooLib.a
- Create the typesystem_foo.xml
Run shiboken with the following command:
shiboken-2.7 global.h --include-paths=.:/opt/local/include/PySide-2.7:/opt/local/include --typesystem-paths=/opt/local/share/PySide-2.7/typesystems --output-directory=../FooLibBinding typesystem_foo.xml
Build the FooLibBinding dynamic library from the resulted generated c++ code --> libFooLibBinding.dylib
Now instead of just running python interpreter from the command line, I made a C++ program which would load the python interpreter and open a .py script using the FooLib. This program links dynamically against libFooLibBinding.dylib so I guess all the symbols needed for the foolib module to work are there;)
here's the code:
#include <iostream>
#include <Python.h>
int main(int argc, char* argv[])
{
///Python init
Py_SetProgramName(argv[0]);
Py_Initialize();
PySys_SetArgv(argc, argv); /// relative module import
///Try out loading the module, this is just for testing
/// -----------
PyObject *sysPath = PySys_GetObject("path");
PyObject *path = PyString_FromString("/Users/alexandre/Downloads/BindingTest");
int result = PyList_Insert(sysPath, 0, path);
PyObject *pModule = PyImport_ImportModule("foolib");
if (PyErr_Occurred())
PyErr_Print();
/// -----------
///Our python file to interpret
const char* filename = "/Users/alexandre/Downloads/BindingTest/FooLibTest/foolib_test.py";
FILE* file = fopen(filename,"r");
PyRun_SimpleFile(file,filename);
///close python
Py_Finalize();
return 0;
}
When running the program, it fails when trying to load the module a first time saying: ImportError: No module named foolib
And then a second time when running the .py script :
Traceback (most recent call last):
File "/Users/alexandre/Downloads/BindingTest/FooLibTest/foolib_test.py", line 1, in <module>
from foolib import FooClass
ImportError: No module named foolib
So obviously it cannot find the module generated from the bindings. My question is what should I do so it can find it ?
The tutorial uses a Makefile but doesn't seem to do much more than just linking the binding dynamic library.