Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

boost::python::numpy causing python crash when numpy not installed

Đang mở
#285 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
30/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp, numpy, python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với điểm vào BOOST_PYTHON_MODULE đã được báo cáo và lệnh gọi np::initialize(), sau đó tái hiện việc import khi không có numpy. Kiểm tra cách quá trình khởi tạo Boost.Python NumPy truyền tiếp ModuleNotFoundError hoặc ImportError trong khi import extension. Hoàn tất có nghĩa là lỗi có thể được Python bắt thay vì làm trình thông dịch kết thúc.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
537
Fork
223
Merge trung bình
11 giờ 22 phút
Pull request đã merge (30 ngày)
2

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của boostorg/python

Tất cả issue của boostorg/python

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.