Digging around, I found that on certain linux (mint in my case, but probably also Ubuntu and Debian) the python library is not loaded with RTLD_LAZY | RTLD_GLOBAL so that all symbols defined there are not accessible from a library loaded at runtime.
I fixed this by adding #include <dlfcn.h> and dlopen("libpython2.7.so", RTLD_LAZY | RTLD_GLOBAL); just before the PythonQt::init(PythonQt::IgnoreSiteModule|PythonQt::RedirectStdOut);
I don't like this since my program is cross platform and it force me to use of #ifdef and moreover this works for a PythonQt compiled with python 2.7 and not for 3.x
Do you ever encouter this issue?
Do you have any advice for a better fix?
many thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
// We need to know the state of Q_OS_LINUX#include<Qt>// The Python header must be included before <QObject> because of name clashes#ifdef Q_OS_LINUX#include"Python.h"#endif// ...intmain(intargc,char*argv[]){#ifdef Q_OS_LINUX// The Python library needs linking directly to the executable as otherwise// Python extension shared objects can't find symbols in the library. This is// because the lookup scope changes for DSOs that are are loaded using dlopen()// (see https://www.akkadia.org/drepper/dsohowto.pdf for details)// This is sufficient to ensure the library is linked to the executablePy_NoUserSiteDirectory=1;#endif// ...}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks David,
I finally found out what caused the error.
I have PyhonQt in my application loaded at runtime as plugin.
The way I was loading this plugin (which in turns load the PythonQt library and then the Python library) by using (a subclass of) QPluginLoader was hiding the symbols in the Python library.
I have a program which uses PythonQt and having some problem when doing a
import numpy
Here is what I get.
Digging around, I found that on certain linux (mint in my case, but probably also Ubuntu and Debian) the python library is not loaded with RTLD_LAZY | RTLD_GLOBAL so that all symbols defined there are not accessible from a library loaded at runtime.
I fixed this by adding
#include <dlfcn.h>
anddlopen("libpython2.7.so", RTLD_LAZY | RTLD_GLOBAL);
just before thePythonQt::init(PythonQt::IgnoreSiteModule|PythonQt::RedirectStdOut);
I don't like this since my program is cross platform and it force me to use of
#ifdef
and moreover this works for a PythonQt compiled with python 2.7 and not for 3.xDo you ever encouter this issue?
Do you have any advice for a better fix?
many thanks
My workaround for this was to do the following:
Thanks David,
I finally found out what caused the error.
I have PyhonQt in my application loaded at runtime as plugin.
The way I was loading this plugin (which in turns load the PythonQt library and then the Python library) by using (a subclass of)
QPluginLoader
was hiding the symbols in the Python library.I had to modify by adding
which I leave here in case someone need.