Calling Python from C++ cannot find or open the PDB file

by Dario2
7 replies
I'm using VS 2010 and I'm trying to call Python function from C++. When I build file, everything is fine, but then it breaks. I followed tutorial https://www.coveros....on-code-from-c/ and it's fine. But when I start debugging it says

1
'C:\Windows\SysWOW64\python27.dll', Cannot find or open the PDB file

I found solution for this here but it's not working for Python. I just cannot find solution for this. Win 8.1, VS 2010 and Python 2.7.
#calling #file #find #open #pdb #python
  • Profile picture of the author wayfarer
    You'll have to show what you've tried before you'll likely get an answer that works.
    Signature
    I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
    {{ DiscussionBoard.errors[10384310].message }}
  • Profile picture of the author Dario2
    Uh sorry, I followed this tutorial https://www.coveros.com/calling-python-code-from-c/
    {{ DiscussionBoard.errors[10386670].message }}
  • Profile picture of the author wayfarer
    I mean show the code you tried it with, what you wrote that didn't work
    Signature
    I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
    {{ DiscussionBoard.errors[10387480].message }}
  • Profile picture of the author Dario2
    Here is C++ code

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <Python.h>
    int _tmain(int argc, _TCHAR* argv[])
    {
    printf("Calling Python to find the sum of 2 and 2.n");
    // Initialize the Python interpreter.
    Py_Initialize();
    // Create some Python objects that will later be assigned values.
    PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;
    // Convert the file name to a Python string.
    pName = PyString_FromString("Sample");
    // Import the file as a Python module.
    pModule = PyImport_Import(pName);
    // Create a dictionary for the contents of the module.
    pDict = PyModule_GetDict(pModule);
    // Get the add method from the dictionary.
    pFunc = PyDict_GetItemString(pDict, "add");
    // Create a Python tuple to hold the arguments to the method.
    pArgs = PyTuple_New(2);
    // Convert 2 to a Python integer.
    pValue = PyInt_FromLong(2);
    // Set the Python int as the first and second arguments to the method.
    PyTuple_SetItem(pArgs, 0, pValue);
    PyTuple_SetItem(pArgs, 1, pValue);
    // Call the function with the arguments.
    PyObject* pResult = PyObject_CallObject(pFunc, pArgs);
    // Print a message if calling the method failed.
    if(pResult == NULL)
    printf("Calling the add method failed.n");
    // Convert the result to a long from a Python object.
    long result = PyInt_AsLong(pResult);
    // Destroy the Python interpreter.
    Py_Finalize();
    // Print the result.
    printf("The result is %d.n", result); std::cin.ignore(); return 0; }
    {{ DiscussionBoard.errors[10391666].message }}
  • Profile picture of the author wayfarer
    Looks like this might be a Visual Studio thing. Have you seen this post? visual studio 2010 - Error Message : Cannot find or open the PDB file - Stack Overflow
    Signature
    I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
    {{ DiscussionBoard.errors[10391994].message }}
  • Profile picture of the author Dario2
    Yes I tried that already. Doesn't work for Python
    {{ DiscussionBoard.errors[10392173].message }}
  • Profile picture of the author wayfarer
    I recommend removing as much code as possible, narrow it down until you find exactly what is triggering the error. It's probably just this line:

    #include <Python.h>

    but I don't want to speculate. Whatever the reason, you need to find out why that PDB file isn't there. Did you try compiling with the /ZI or /Zi options enabled like suggested (in the linked post)?
    Signature
    I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
    {{ DiscussionBoard.errors[10393681].message }}

Trending Topics