Skip to content

Cannot seem to embed Python 3.11 into a 64-bit Windows C++ program #115919

@dannypike

Description

@dannypike

I cannot get the examples in the C API documentation to work on a 64-bit Windows application. The problem appears to be that the initialization code cannot find a codec for the "utf8" that it chooses to use when I call the Py_InitializeFromConfig() method.

Hopefully this is a simple problem, caused by my ignorance of Python-history. I've built a debug version of python311_d.dll to allow me to step through the source and the problem appears to be that this code fails:

    mod = PyImport_ImportModule("encodings");

Presumably because it cannot find a module called "encodings". Would some kind soul please tell me how I make that module available in the C API and update the documentation?

Thanks,

Dan

Edit:

This is an "isolated" embedding. Here's the code that I am using in my most recent attempt:

      PyPreConfig_InitIsolatedConfig(&preCfg_);
      preCfg_.utf8_mode = 1;
      PyPreConfig_InitIsolatedConfig(&preCfg_);
      PyConfig_InitIsolatedConfig(&cfg_);

      status_ = PyConfig_SetBytesArgv(&cfg_, argc, argv);
      if (PyStatus_Exception(status_)) {
         return false;
      }

      status_ = Py_InitializeFromConfig(&cfg_);
      //PyConfig_Clear(&cfg_);
      if (PyStatus_Exception(status_)) {
         return false;
      }

I've tried quite a few variants on the above, but maybe there's some magic option that I haven't noticed?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions