From 5e61d9659b1fc3b5219f787224558c4389b48d41 Mon Sep 17 00:00:00 2001 From: Mateo Gianolio Date: Fri, 26 Apr 2019 11:12:51 +0200 Subject: [PATCH 1/5] hopefully fixes numpy import error --- .gitignore | 1 + binding.gyp | 3 +++ package.json | 2 +- src/matplotlib.h | 25 +++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e3fbd98..fb40ccb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build node_modules +.vscode diff --git a/binding.gyp b/binding.gyp index fe4edd9..4bcfe40 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,6 +3,9 @@ { "target_name": "matplotlib", "sources": [ "src/matplotlib.cc" ], + "include_dirs": [ + " +#endif // WITHOUT_NUMPY + namespace plt { struct interpreter { public: @@ -36,6 +41,22 @@ namespace plt { return context; } private: +#ifndef WITHOUT_NUMPY +# if PY_MAJOR_VERSION >= 3 + + void *import_numpy() { + import_array(); // initialize C-API + return NULL; + } + +# else + + void import_numpy() { + import_array(); // initialize C-API + } + +# endif +#endif interpreter() { #if PY_MAJOR_VERSION >= 3 wchar_t name[] = L"matplotnode"; @@ -45,6 +66,10 @@ namespace plt { Py_SetProgramName(name); Py_Initialize(); +#ifndef WITHOUT_NUMPY + import_numpy(); // initialize numpy C-API +#endif + PyObject *matplotlibname = PyString_FromString("matplotlib"); PyObject* matplotlib = PyImport_Import(matplotlibname); Py_DECREF(matplotlibname); From d27dde5330c53837b61cc7e340e9300d64a59984 Mon Sep 17 00:00:00 2001 From: Mateo Gianolio Date: Fri, 26 Apr 2019 11:29:30 +0200 Subject: [PATCH 2/5] try dlopen call --- package-lock.json | 2 +- src/matplotlib.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 9d18b99..054410d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { "name": "matplotnode", - "version": "0.3.1", + "version": "0.3.2", "lockfileVersion": 1 } diff --git a/src/matplotlib.h b/src/matplotlib.h index 67a360f..4c811ec 100644 --- a/src/matplotlib.h +++ b/src/matplotlib.h @@ -64,6 +64,11 @@ namespace plt { char name[] = "matplotnode"; #endif Py_SetProgramName(name); + +#ifdef linux + dlopen("libpython2.7.so", RTLD_LAZY | RTLD_GLOBAL); +#endif + Py_Initialize(); #ifndef WITHOUT_NUMPY From 8d857e78f391a2ed79184b509bfa4d3df02332a4 Mon Sep 17 00:00:00 2001 From: Mateo Gianolio Date: Fri, 26 Apr 2019 11:31:41 +0200 Subject: [PATCH 3/5] ../.. --- binding.gyp | 3 ++- src/matplotlib.h | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/binding.gyp b/binding.gyp index 4bcfe40..af6ce0a 100644 --- a/binding.gyp +++ b/binding.gyp @@ -21,7 +21,8 @@ " #include +#ifdef linux + #include +#endif + #if PY_MAJOR_VERSION >= 3 #define PyString_FromString PyUnicode_FromString #endif #ifndef WITHOUT_NUMPY -# define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION -# include + #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION + #include #endif // WITHOUT_NUMPY namespace plt { From 3022c3013534e0f6afa52d6dc71853b4753ecb8b Mon Sep 17 00:00:00 2001 From: Mateo Gianolio Date: Fri, 26 Apr 2019 11:33:52 +0200 Subject: [PATCH 4/5] ... --- binding.gyp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index af6ce0a..bcc0dc2 100644 --- a/binding.gyp +++ b/binding.gyp @@ -6,6 +6,9 @@ "include_dirs": [ " Date: Fri, 26 Apr 2019 11:35:58 +0200 Subject: [PATCH 5/5] added dlopen for python3 --- src/matplotlib.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/matplotlib.h b/src/matplotlib.h index 2a7030d..29556f8 100644 --- a/src/matplotlib.h +++ b/src/matplotlib.h @@ -70,7 +70,11 @@ namespace plt { Py_SetProgramName(name); #ifdef linux +#if PY_MAJOR_VERSION >= 3 + dlopen("libpython3.so", RTLD_LAZY | RTLD_GLOBAL); +#else dlopen("libpython2.7.so", RTLD_LAZY | RTLD_GLOBAL); +#endif #endif Py_Initialize();