Rakete1111 Rakete1111 - 1 year ago 398
C Question

PyImport_Import fails - Returns NULL

First off, yes I have seen this and this, however they didn't resolve my problem/error.

So, I'm trying to call a Python function from C/C++, but when
is called it returns


PyObject* fname = PyBytes_FromString("hello");
PyObject* module = PyImport_Import(fname);

is my
file in the same directory as the executable. I have no idea where my error is, could some please point me to it?

Answer Source

I thought that PyBytes_FromString was the the 3.x alternative of PyString_From.

I was wrong. PyUnicode_FromString is the correct alternative.

(Thanks to @wakjah for given me the tip of using error handling)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download