Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

numpy required for C++ library to work with python bindings

Open
#358 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp, python
Domain
api

Research direction

Start by reproducing the failure with the shown BOOST_PYTHON_MODULE(test_lib) entry point, comparing Python runs with and without importing numpy first. Trace the initialization path behind test_lib.initialize() and gather enough source to determine whether the numpy import is required; done means explaining the dependency or identifying the failing initialization step.

Written by the indexing model from the issue text.

Description

I've added Boost python bindings into a C++ library. Calling the initialization method of this C++ library from python will fail if numpy is not imported into python before importing my C++ library. There are no errors but the C++ library spits out it failed to initialize. Why would numpy be required in python for my boost bindings to work with this C++ library? See example below.

C++

// Boost imports I'm using
#include <boost/python.hpp>
#include <boost/python/dict.hpp>
#include <boost/python/object.hpp>
using namespace boost;

static bool InitializePy() {
    // Call library initialize here
}

BOOST_PYTHON_MODULE(test_lib)
{
    python::def("initialize", InitializePy);
}

Python

# import numpy
import test_lib
# Without importing numpy, this initialization will fail
test_lib.initialize()

I can share more source if anyone would like a look but the way I see it, regardless of what else is being done in C++, numpy needing to be imported in python is odd to me.

Dominant language
C++
Stars
537
Forks
223
Avg merge
11h 22m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/python

All issues in boostorg/python

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.