Apologies this isn't as such an issue report, but seeking clarification: Jython 2.7.x
For reasons outside of my control, I am forced to use single, large script files.. I write extensions to an app which controls the environment my code executes in (code is started / run by the master app through PythonInterpreter).
I cannot do 'normal' imports as my code runs from within a ZIP file. I can get the zip resources and contents via classloader.getResourceAsStream() etc.
Because I have large files, I sometimes hit the:
java.lang.RuntimeException: Module or method too large in xxx.py
and it then says:
Please provide a CPython 2.7 bytecode file (.pyc), e.g. run
python -m py_compile xxx.py
Alternatively, specify a CPython 2.7 command via the python.cpython2 property, e.g.:
jython -Dpython.cpython2=python
or (e.g. for pip) through the environment variable JYTHON_OPTS:
So, question 1. Why is it saying use python -m for jython?
question 2: is it actually possible to create .pyc files for jython, and if so, how do you actually do it?
question 3: what is the difference between .pyc files and xxx$py.class files?
I have now managed to compile jython using:
java -cp jython.jar org.python.util.jython -c "import compileall; compileall.compile_file('xx.py')"
.. and run it using imp.load_module() so this bit is great! But of course the script ends up within a sub module scope whereas I really want it within the scope of the original script. (Hence execfile would be more useful).
question 4: is there a way to execute $py.class files using execfile() via a resource stream (like load_module) rather than from a file?
question 5: I see exec can run Code objects.... What is this Code object? Is it the same as a .pyc file and/or $py.class file? And again, can a stream be executed rather than a file....?
Separately, I have seen that execfile() on a script which hits the too large issue, does actually run if a .pyc is also present on disk in the same location and one that was compiled by python -m py_compile... So something with pyc works... This all seems very odd..!?
Sorry for the questions, I have done much reading and experimenting. I am glad I have finally got something working, but your clarification(s) would be appreciated?
Thanks
Apologies this isn't as such an issue report, but seeking clarification: Jython 2.7.x
For reasons outside of my control, I am forced to use single, large script files.. I write extensions to an app which controls the environment my code executes in (code is started / run by the master app through PythonInterpreter).
I cannot do 'normal' imports as my code runs from within a ZIP file. I can get the zip resources and contents via classloader.getResourceAsStream() etc.
Because I have large files, I sometimes hit the:
java.lang.RuntimeException: Module or method too large in xxx.py
and it then says:
Please provide a CPython 2.7 bytecode file (.pyc), e.g. run
python -m py_compile xxx.py
Alternatively, specify a CPython 2.7 command via the python.cpython2 property, e.g.:
jython -Dpython.cpython2=python
or (e.g. for pip) through the environment variable JYTHON_OPTS:
So, question 1. Why is it saying use python -m for jython?
question 2: is it actually possible to create .pyc files for jython, and if so, how do you actually do it?
question 3: what is the difference between .pyc files and xxx$py.class files?
I have now managed to compile jython using:
java -cp jython.jar org.python.util.jython -c "import compileall; compileall.compile_file('xx.py')"
.. and run it using imp.load_module() so this bit is great! But of course the script ends up within a sub module scope whereas I really want it within the scope of the original script. (Hence execfile would be more useful).
question 4: is there a way to execute $py.class files using execfile() via a resource stream (like load_module) rather than from a file?
question 5: I see exec can run Code objects.... What is this Code object? Is it the same as a .pyc file and/or $py.class file? And again, can a stream be executed rather than a file....?
Separately, I have seen that execfile() on a script which hits the too large issue, does actually run if a .pyc is also present on disk in the same location and one that was compiled by python -m py_compile... So something with pyc works... This all seems very odd..!?
Sorry for the questions, I have done much reading and experimenting. I am glad I have finally got something working, but your clarification(s) would be appreciated?
Thanks