This piece of code is part of one of my wxFrames for a sign up page. I am trying to run some Python code from C++ in order to switch frames, depending on the output of the Python file.
(I use this: namespace pb = pybind11; in order to refer to pybind11 just by pb)
I have done some debugging and find that this line of code is causing a problem.
pb::module python_module = pb::module::import("python_functions");
No error is returned, the program just doesn't continue.
I have spent all day trying to fix this bug and I am now out of ideas. The name of the Python file is correct, the Python file is in the same directory as the VS project, I have changed loads of PATHS in order for C++ to run the Python interpreter (maybe I've missed something??)
I have tested the Python code by itself and it works absolutely perfectly so it can't be the Python it's definitely that line of code. Here is the rest of the code:
std::string python_username_input = input_values[0].ToStdString();
// convert the inputs into a string that Python can interpret
std::string python_password_input = input_values[1].ToStdString();
pb::scoped_interpreter guard{};
pb::module sys = pb::module::import("sys"); // Import sys module
sys.attr("path").attr("append")("[DIRECTORY TO FILE]");
pb::module python_module = pb::module::import("python_functions");
pb::object python_result = python_module.attr("SignUp")(python_username_input, python_password_input, check_values[0]);
Any help would be appreciated, this is for a project and I really need to get this sorted out. If you think you may need more context/code in order to work out the problem then please let me know. Maybe I need to #include another library? I have included '#include <pybind11/embed.h>' so maybe I'm missing something else?
Anyway, thank you for any response.
py::evaleverything from importing to actually executing. I think the problem is thatpy::module::importis not using the interpreter, so it doesn't see your modification tosys.path, but the function doesn't document how the lookup is performed.