Problem: Strange exception is thrown when embedding Python with C++.
Program:
bool embedd::execute_python(std::string location)
{
if (std::ifstream(location))
{
const char* file_location = location.c_str();
FILE* file_pointer;
// Initialize the Python interpreter
Py_Initialize();
file_pointer = _Py_fopen(file_location, "r");
// Run the Python file
PyRun_SimpleFile(file_pointer, file_location);
// Finalize the Python interpreter
Py_Finalize();
return true;
}
return false;
}
What does the above code snippet should do: The function should first check whether the passed argument is a valid location of the python file. If the file is present then it should execute the Python file.
Am I getting expected results: yes and no.
what is going wrong:
Test file 1:
print("Hello world")
Result : Successful execution and getting proper output
Test file 2:
from tkinter import *
root = Tk()
root.mainloop()
Result : Exception root = Tk() File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\Lib\tkinter__init__.py", line 1863, in init baseName = os.path.basename(sys.argv[0]) AttributeError: module 'sys' has no attribute 'argv'
Tested with some other file and found that when-ever we import modules(any) like tkinter, uuid, os etc similar exception gets thrown. on digging briefly about this the process monitor of my IDE told "Symbol file is not loaded" e.g no symbol file loaded for tk86t.dll
Python Version : 3.5.2
Links which I do have referred: SO - 1 found the bug has been fixed from Python 2.3 here BUGS