1

I linked Python 3.8.7 dynamically to a Visual Studio C++ console application TestPython.exe with the following code to try plistlib library (which is necessary in my real application):

#include <iostream>

#include "Python.h"

int main()
{
    std::string name;
    std::cout << "Write name:   ";
    std::cin >> name;

    std::cout << "name: " << name << "\n";

    Py_Initialize();

    PyObject* moduleMainString = PyUnicode_FromString("__main__");
    PyObject* moduleMain = PyImport_Import(moduleMainString);

    PyRun_SimpleString(
        "import plistlib\n"\
        "def testDict(a):\n"
        "   pl = dict(aString = a)\n"\
    );

    PyObject* func = PyObject_GetAttrString(moduleMain, "testDict");
    PyObject* args = PyTuple_Pack(1, PyUnicode_FromString(name.c_str()));
    PyObject* result = PyObject_CallObject(func, args);

    Py_Finalize();

    system("pause");
}

In my developer computer (where I have Python installed) the executable works well. When I run it in a different computer with no Python installed, the application shows the following error:

Traceback (most recent call last):
   File "<string>", line 1, in <module>
   File "<frozen zipimport>", line 259, in load_module
   File "plistlib.py", line 65, in <module>
   File "<frozen zipimport>", line 259, in load_module
   File "xml\parser\expat.py", line 4, in <module>
ModuleNotFoundError: No module named 'pyexpat'

error picture

When I run it in a different computer I took care of including in the same directory:

The Python files bundled with TestPython.exe properly match the Python version of the developer computer (this was typically the solution in related 'pyexpat' questions, but not for this one).

1
  • thx for not posting only the image of the error message Commented Feb 26, 2021 at 17:53

1 Answer 1

2

Solution: place ALL files found in the Python 3.8.7 Windows embeddable package in the same directory (not just the .dll and .zip). In particular, there is file pyexpat.pyd which was missing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.