boost::python::numpy causing python crash when numpy not installed
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 30/100
Rechercherichtung
Beginne mit dem gemeldeten BOOST_PYTHON_MODULE-Einstiegspunkt und dem Aufruf von np::initialize(), und reproduziere dann den Import, wenn numpy nicht vorhanden ist. Untersuche, wie die Boost.Python-NumPy-Initialisierung ModuleNotFoundError oder ImportError während des Imports der Erweiterung weitergibt. Erledigt bedeutet, dass der Fehler von Python abgefangen werden kann, anstatt den Interpreter zu beenden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
The following code causes python to exit (crash?) upon import when numpy is not installed. It looks like a ModuleNotFoundError does get thrown but it's not catchable and python simply exits. It's hard to tell if this is exit() being called or an actual crash. I would expect a catchable ModuleNotFoundError or ImportError to be thrown and python not to exit.
#define BOOST_PYTHON_STATIC_LIB
#define BOOST_NUMPY_STATIC_LIB
#include <boost/python.hpp>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <boost/python/numpy.hpp>
namespace py = boost::python;
namespace np = boost::python::numpy;
template<class T>
np::ndarray to_numpy(const std::vector<T> &vec)
{
Py_intptr_t shape[1] = { static_cast<Py_intptr_t>(vec.size()) };
np::ndarray result = np::zeros(1, shape, np::dtype::get_builtin<T>());
std::copy(vec.begin(), vec.end(), reinterpret_cast<T*>(result.get_data()));
return result;
}
BOOST_PYTHON_MODULE(HelloBoostPython)
{
np::initialize();
py::class_<std::vector<double>>("DoubleVector")
.def(py::init<size_t>())
.def(py::init<size_t, const double&>())
.def(py::vector_indexing_suite<std::vector<double>>())
.def("to_numpy", to_numpy<double>)
;
}
prompt:
(base) C:\Development\HelloBoostPython\Debug>python
Python 3.7.4 (default, Aug 9 2019, 18:22:51) [MSC v.1915 32 bit (Intel)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import HelloBoostPython
ModuleNotFoundError: No module named 'numpy'
ImportError: numpy.core._multiarray_umath failed to import
(base) C:\Development\HelloBoostPython\Debug>
If it matters, this is with boost 1.70 using visual studio 2017 to build.
- Vorherrschende Sprache
- C++
- Sterne
- 537
- Forks
- 223
- Ø Merge
- 11 Std. 22 Min.
- Gemergte PRs (30 T.)
- 2
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus boostorg/python
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
-
BoostDetectToolset-1.90.0.cmake file not found in an include() call in boost_python-config.cmake Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
Alle Issues in boostorg/python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
objectionary/eo-graphs#74 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 95/100
-
enhancement
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
QuantStack/git2cpp#187 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100