• Create Account

### #ActualShaquil

Posted 05 November 2012 - 09:33 PM

I've embedded Python into C++ successfully (without even remotely as much pain and agony as with Lua). Now when I run a simple test program, the console window opens and closes immediately. It definitely executes the way it should with no problems, however I seem to be unable to stop it from closing immediately. I've called system("PAUSE") and added cin >> variable so the program basically has absolutely no choice but to wait for input, yet these things are somehow ignored. I'm on Windows 7 using Visual Studio 2012. Here's the code:

#include <Python.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);  /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
int x = 0;
cin >> x;
system("PAUSE");

return 0;
}


Any idea what's going on here? Oddly, when I place that code that's supposed to pause it


int x = 0;
cin >> x;
system("PAUSE");


in BEFORE all the python code, it does actually stop. Even worse: I've used breakpoints. If placed on or before the call to Py_Initialize(), the code stops at the breakpoint. Anywhere else, the breakpoint is never reached. Strangely, VC++ will usually tell you if a breakpoint will never be reached, however it seems to believe that the breakpoints placed after Py_Initialize() will be reached.

UPDATE::

So apparently there's an error occuring. I barely noticed it. What happens is, a message is output "Import Error: No module named site." The program then closes immediately. Any ideas? I'm googling now, and I'll be back with another update if I find an answer, for future readers.

### #3Shaquil

Posted 05 November 2012 - 09:33 PM

I've embedded Python into C++ successfully (without even remotely as much pain and agony as with Lua). Now when I run a simple test program, the console window opens and closes immediately. It definitely executes the way it should with no problems, however I seem to be unable to stop it from closing immediately. I've called system("PAUSE") and added cin >> variable so the program basically has absolutely no choice but to wait for input, yet these things are somehow ignored. I'm on Windows 7 using Visual Studio 2012. Here's the code:

#include <Python.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);  /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
int x = 0;
cin >> x;
system("PAUSE");

return 0;
}


Any idea what's going on here? Oddly, when I place that code that's supposed to pause it


int x = 0;
cin >> x;
system("PAUSE");


in BEFORE all the python code, it does actually stop. Even worse: I've used breakpoints. If placed on or before the call to Py_Initialize(), the code stops at the breakpoint. Anywhere else, the breakpoint is never reached. Strangely, VC++ will usually tell you if a breakpoint will never be reached, however it seems to believe that the breakpoints placed after Py_Initialize() will be reached.

UPDATE::

So apparently there's an error occuring. I barely noticed it. What happens is, a message is output "Import Error: No module named site." The program then closes immediately. Any ideas? I'm googling now, and I'll be back with another update if I find an answer, for future readers.

### #2Shaquil

Posted 05 November 2012 - 09:33 PM

I've embedded Python into C++ successfully (without even remotely as much pain and agony as with Lua). Now when I run a simple test program, the console window opens and closes immediately. It definitely executes the way it should with no problems, however I seem to be unable to stop it from closing immediately. I've called system("PAUSE") and added cin >> variable so the program basically has absolutely no choice but to wait for input, yet these things are somehow ignored. I'm on Windows 7 using Visual Studio 2012. Here's the code:

#include <Python.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);  /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
int x = 0;
cin >> x;
system("PAUSE");

return 0;
}


Any idea what's going on here? Oddly, when I place that code that's supposed to pause it


int x = 0;
cin >> x;
system("PAUSE");


in BEFORE all the python code, it does actually stop. Even worse: I've used breakpoints. If placed on or before the call to Py_Initialize(), the code stops at the breakpoint. Anywhere else, the breakpoint is never reached. Strangely, VC++ will usually tell you if a breakpoint will never be reached, however it seems to believe that the breakpoints placed after Py_Initialize() will be reached.

UPDATE::

So apparently there's an error occuring. I barely noticed it. What happens is, a message is output "Import Error: No module named site." Any ideas? I'm googling now, and I'll be back with another update if I find an answer, for future readers.

### #1Shaquil

Posted 05 November 2012 - 09:13 PM

I've embedded Python into C++ successfully (without even remotely as much pain and agony as with Lua). Now when I run a simple test program, the console window opens and closes immediately. It definitely executes the way it should with no problems, however I seem to be unable to stop it from closing immediately. I've called system("PAUSE") and added cin >> variable so the program basically has absolutely no choice but to wait for input, yet these things are somehow ignored. I'm on Windows 7 using Visual Studio 2012. Here's the code:

#include <Python.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);  /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
int x = 0;
cin >> x;
system("PAUSE");

return 0;
}


Any idea what's going on here? Oddly, when I place that code that's supposed to pause it


int x = 0;
cin >> x;
system("PAUSE");


in BEFORE all the python code, it does actually stop. Even worse: I've used breakpoints. If placed on or before the call to Py_Initialize(), the code stops at the breakpoint. Anywhere else, the breakpoint is never reached. Strangely, VC++ will usually tell you if a breakpoint will never be reached, however it seems to believe that the breakpoints placed after Py_Initialize() will be reached.

PARTNERS