shams.haq
shams.haq

Reputation: 714

use .pyc files via Jython

I am working on building a web interface for a Python tool. It's being designed using J2EE (Spring).

In the process, I need to make calls to Python functions and hence I am using Jython for the same.

But for some modules I don't have the Python source files, I only have the .pyc files, and a document listing the methods of that file. I need to know how I can call these functions inside the .pyc file using jython.

I have tried to de-compile the Python files but since they have been complied with Python 2.7, I am not able find a decompiler to do the job

Upvotes: 0

Views: 1402

Answers (2)

Alan Kennedy
Alan Kennedy

Reputation: 131

Actually, jython does have experimental support for running cpython-generated pyc files: jython 2.5 has a cpython bytecode interpreter built in.

Read more about how to use it here

http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html?highlight=pycimport#compilation

Upvotes: 2

Jacek Konieczny
Jacek Konieczny

Reputation: 8604

The 'compiled' python code '.pyc' files are implementation-specific. Even CPython (the standard Python implementation) is not able to import .pyc files generated by a different version of CPython. And is not supposed to. So, I would be surprised if Jython had an ability to run .pyc files created by any of CPython version.

'.pyc' files are not the same as Java bytecode (which is designed to be portable).

Decompilation seems the only way. I think there are some .pyc decompilers available, they should be able to generate Python code that could be run by Jython.

Upvotes: 3

Related Questions