Hello everyone ..
Im new in python and i have a question !
How to compile myfile.py to myfile.pyo ?
Can you give me an example script coz i dont know were to put python -0 to compile it into pyo !
Thanks a lot ..
Hello everyone ..
Im new in python and i have a question !
How to compile myfile.py to myfile.pyo ?
Can you give me an example script coz i dont know were to put python -0 to compile it into pyo !
Thanks a lot ..
A .pyo is just Python 2.x bytecode written with optimizations enabled. That means you need to run the interpreter in optimized mode when you compile. Building one file from the command line looks like this:
# Linux/macOS
python -O -m py_compile myfile.py
# Windows
python -O -m py_compile myfile.py To precompile a whole folder, use compileall the same way:
python -O -m compileall path/to/your/project You can also drive this with the environment variable that @Ene Uran hinted at: on Linux/macOS PYTHONOPTIMIZE=1 python -m py_compile myfile.py; on Windows set PYTHONOPTIMIZE=1 && python -m py_compile myfile.py. Use -OO or PYTHONOPTIMIZE=2 only if you are fine with docstrings being stripped. See the Python 2.7 command line docs for -O/-OO and PYTHONOPTIMIZE. Command line and environment (Python 2.7) and compileall docs.
Important runtime detail: CPython will only import .pyo files when it is running in optimized mode. If you start Python normally, it will ignore .pyo and use .py/.pyc instead. That is why ’s pure-Python snippet typically yields .pyc (the interpreter was not started with -O). If you cannot control the -O flag at runtime, stick with .pyc.
For PyS60 specifically, you generally compile on your PC and copy the resulting .pyc/.pyo to the phone as a library module; the phone does not usually write bytecode caches itself. Make sure you compile with the same major.minor Python version that your PyS60 build uses, otherwise the bytecode will not load. Nokia’s Getting Started guide for Python for Series 60 notes that .pyc/.pyo created on another platform can be moved to the phone and installed as libraries. Getting Started with Python for Series 60.
Note for future readers: modern Python (3.5+) no longer produces .pyo; optimized bytecode is stored as .pyc with an opt tag. PEP 488.
Jump to Post— ryantroop 177http://www.velocityreviews.com/forums/t346147-generating-pyo-from-py.html
If it is not clear from the example, those are command line scripts; i.e., what you use to start up python in the first place.
Jump to Post— ryantroop 177I am not familliar with pys60... I suppose you could manually force a compile.
try making a script that is in the same directory called compileme.py:
import py_compile py_compile.compile("yourscript.py")save, and run it.
This may end up with a .pyc file, though (it shouldnt be any …
http://www.velocityreviews.com/forums/t346147-generating-pyo-from-py.html
If it is not clear from the example, those are command line scripts; i.e., what you use to start up python in the first place.
im using pys60 and i want to compile myfile.py to myfile.pyo ! Is there a example code on how to compile ? coz i dont have any idea ..
I am not familliar with pys60... I suppose you could manually force a compile.
try making a script that is in the same directory called compileme.py:
import py_compile
py_compile.compile("yourscript.py")
save, and run it.
This may end up with a .pyc file, though (it shouldnt be any different, I believe)... and that's also assuming py_compile is included with your distribution of python...
Look under PYTHONOPTIMIZE in the Python manual.
pyo, is os dependent i think, and there is no way to compile a py to pyo on the phone. you can compile or decompile py/pyc files using many apps out there as symbian packages (e.g. BestDeCompiler.sis).
if you make a pyo on pc from a pys60 script, i think it wont run on your phone.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.