Embeddor Woes...

P

Preston H

Hello, someone may have tackled this problem before but I have
searched the google newsgroups up and down and I can't find anything
on this. I am trying to write an embedded python program in C++ that
will go out and execute python language in a script.

I am using Visual C++ .NET, and I do have Multithreaded DLL(/MD)
turned on for the Runtime Library, I have the Python 2.2 installed and
their include and libs directories are set. Also, I have Visual C++
..NET set to release version, mainly because I cannot find
python22_d.dll anywhere.

This is the error that I get when I successfully compile this program
and try to run it at a dos prompt...

The instruction at "0x77f85c41" referenced memory at "0x00000010".
The memory could not be "written".

This is the source code that I am trying to test...

#include "python.h"
#include <stdio.h>

int main(int argc, char* argv[])
{
char *filename = "test.py";

FILE *OurFile = fopen(filename, "r+");

Py_Initialize();

PyRun_SimpleFile(OurFile, "test.py");

Py_Finalize();

return 0;
}

Like I said earlier, the program compiles without any hitches. Any
help on this is appreciated very much!
 
R

Roel Vanhout

Have you tried to use embedding.cpp from the boost.python examples? It
will show if your configuration is working OK; if it is, the problem is
obviously in your program. At first sight I'd say that your test.py
can't be found - did you set the right working directories?

cheers,

roel


Preston said:
Hello, someone may have tackled this problem before but I have
searched the google newsgroups up and down and I can't find anything
on this. I am trying to write an embedded python program in C++ that
will go out and execute python language in a script.

I am using Visual C++ .NET, and I do have Multithreaded DLL(/MD)
turned on for the Runtime Library, I have the Python 2.2 installed and
their include and libs directories are set. Also, I have Visual C++
.NET set to release version, mainly because I cannot find
python22_d.dll anywhere.

This is the error that I get when I successfully compile this program
and try to run it at a dos prompt...

The instruction at "0x77f85c41" referenced memory at "0x00000010".
The memory could not be "written".

This is the source code that I am trying to test...

#include "python.h"
#include <stdio.h>

int main(int argc, char* argv[])
{
char *filename = "test.py";

FILE *OurFile = fopen(filename, "r+");

Py_Initialize();

PyRun_SimpleFile(OurFile, "test.py");

Py_Finalize();

return 0;
}

Like I said earlier, the program compiles without any hitches. Any
help on this is appreciated very much!
 
R

Roel Vanhout

Have you tried to use embedding.cpp from the boost.python examples? It
will show if your configuration is working OK; if it is, the problem is
obviously in your program. At first sight I'd say that your test.py
can't be found - did you set the right working directories?

cheers,

roel


Preston said:
Hello, someone may have tackled this problem before but I have
searched the google newsgroups up and down and I can't find anything
on this. I am trying to write an embedded python program in C++ that
will go out and execute python language in a script.

I am using Visual C++ .NET, and I do have Multithreaded DLL(/MD)
turned on for the Runtime Library, I have the Python 2.2 installed and
their include and libs directories are set. Also, I have Visual C++
.NET set to release version, mainly because I cannot find
python22_d.dll anywhere.

This is the error that I get when I successfully compile this program
and try to run it at a dos prompt...

The instruction at "0x77f85c41" referenced memory at "0x00000010".
The memory could not be "written".

This is the source code that I am trying to test...

#include "python.h"
#include <stdio.h>

int main(int argc, char* argv[])
{
char *filename = "test.py";

FILE *OurFile = fopen(filename, "r+");

Py_Initialize();

PyRun_SimpleFile(OurFile, "test.py");

Py_Finalize();

return 0;
}

Like I said earlier, the program compiles without any hitches. Any
help on this is appreciated very much!
 
K

Kerim

PyRun_SimpleFile doesn't work for me too.

As a workaround I suggest to replace it with:
PyRun_SimpleString("execfile('test.py')");

Kerim

Roel Vanhout said:
Have you tried to use embedding.cpp from the boost.python examples? It
will show if your configuration is working OK; if it is, the problem is
obviously in your program. At first sight I'd say that your test.py
can't be found - did you set the right working directories?

cheers,

roel


Preston said:
Hello, someone may have tackled this problem before but I have
searched the google newsgroups up and down and I can't find anything
on this. I am trying to write an embedded python program in C++ that
will go out and execute python language in a script.

I am using Visual C++ .NET, and I do have Multithreaded DLL(/MD)
turned on for the Runtime Library, I have the Python 2.2 installed and
their include and libs directories are set. Also, I have Visual C++
.NET set to release version, mainly because I cannot find
python22_d.dll anywhere.

This is the error that I get when I successfully compile this program
and try to run it at a dos prompt...

The instruction at "0x77f85c41" referenced memory at "0x00000010".
The memory could not be "written".

This is the source code that I am trying to test...

#include "python.h"
#include <stdio.h>

int main(int argc, char* argv[])
{
char *filename = "test.py";

FILE *OurFile = fopen(filename, "r+");

Py_Initialize();

PyRun_SimpleFile(OurFile, "test.py");

Py_Finalize();

return 0;
}

Like I said earlier, the program compiles without any hitches. Any
help on this is appreciated very much!


--

--
Roel Vanhout - Programmer/Systems Administrator
RIKS BV
Papenstraat 8 - 6211 LG Maastricht
Tel +31 (0)43 388 3708 - Fax +31 (0)43 325 3155
 
P

Preston H

That did it... I wonder why PyRun_SimpleFile or PyRun_File won't
work? Do I have to recompile the python source under MSVC++.NET?

Kerim said:
PyRun_SimpleFile doesn't work for me too.

As a workaround I suggest to replace it with:
PyRun_SimpleString("execfile('test.py')");

Kerim

Roel Vanhout said:
Have you tried to use embedding.cpp from the boost.python examples? It
will show if your configuration is working OK; if it is, the problem is
obviously in your program. At first sight I'd say that your test.py
can't be found - did you set the right working directories?

cheers,

roel


Preston said:
Hello, someone may have tackled this problem before but I have
searched the google newsgroups up and down and I can't find anything
on this. I am trying to write an embedded python program in C++ that
will go out and execute python language in a script.

I am using Visual C++ .NET, and I do have Multithreaded DLL(/MD)
turned on for the Runtime Library, I have the Python 2.2 installed and
their include and libs directories are set. Also, I have Visual C++
.NET set to release version, mainly because I cannot find
python22_d.dll anywhere.

This is the error that I get when I successfully compile this program
and try to run it at a dos prompt...

The instruction at "0x77f85c41" referenced memory at "0x00000010".
The memory could not be "written".

This is the source code that I am trying to test...

#include "python.h"
#include <stdio.h>

int main(int argc, char* argv[])
{
char *filename = "test.py";

FILE *OurFile = fopen(filename, "r+");

Py_Initialize();

PyRun_SimpleFile(OurFile, "test.py");

Py_Finalize();

return 0;
}

Like I said earlier, the program compiles without any hitches. Any
help on this is appreciated very much!


--

--
Roel Vanhout - Programmer/Systems Administrator
RIKS BV
Papenstraat 8 - 6211 LG Maastricht
Tel +31 (0)43 388 3708 - Fax +31 (0)43 325 3155
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,436
Latest member
MaxD

Latest Threads

Top