By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,085 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

Embedding Python: How to run compiled(*.pyc/*.pyo) files using Python C API?

P: n/a
Hello,

I am trying to run compiled Python files (*.pyc and *.pyo) using Python C
API.

I am using the method PyRun_FileFlags() for this purpose.

The code snippet is as follows:-

PyCompilerFlags myFlags;
myFlags.cf_flags=1; // I tried all values 0, 1 and 2
PyRun_FileFlags(script, file, Py_file_input, globals, locals, &myFlags);

But unfortunately I get the following exception:-
"DeprecationWarning: Non-ASCII character '\xf2' in file E:\test.pyc on line
1, but no encoding declared; see http://www.python.org/peps/pep-0263.html
for details"

When I run the .py file, then things work fine.
The .py file contains only one statement,
print "Hello World"

Which Python C API should I use to run compiled Python files(*.pyc and
*.pyo) in the scenario where the source file (*.py) is not present.

Thanks in advance,
Regards,
Shankar

May 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Shankar wrote:
Hello,

I am trying to run compiled Python files (*.pyc and *.pyo) using Python C
API.

I am using the method PyRun_FileFlags() for this purpose.

The code snippet is as follows:-

PyCompilerFlags myFlags;
myFlags.cf_flags=1; // I tried all values 0, 1 and 2
PyRun_FileFlags(script, file, Py_file_input, globals, locals, &myFlags);

But unfortunately I get the following exception:-
"DeprecationWarning: Non-ASCII character '\xf2' in file E:\test.pyc on line
1, but no encoding declared; see http://www.python.org/peps/pep-0263.html
for details"
Note, it's not an exception, it's a warning.

When I run the .py file, then things work fine.
The .py file contains only one statement,
print "Hello World"

Which Python C API should I use to run compiled Python files(*.pyc and
*.pyo) in the scenario where the source file (*.py) is not present.


I believe it's PyImport_ImportModule("test")

May 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.