Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is .pyc platform independent?

I recently started python development on raspberry pi. While reading about .pyc file to speed up the start up, I was wondering if I test a .pyc file on PC, given that same python modules are available on Rpi, will it work directly ? Please also include what happens if python version or any of module version differs on target platform.

Thanks in advance.

like image 843
dhruvvyas90 Avatar asked May 25 '15 17:05

dhruvvyas90


People also ask

Is PYC file platform independent?

pyc" file is platform independent, so a Python module directory can be shared by machines of different architectures. Some tips for experts: When the Python interpreter is invoked with the -O flag, optimized code is generated and stored in ". pyo" files.

What is the difference between .py and .PYC files?

. py files contain the source code of a program. Whereas, . pyc file contains the bytecode of your program.

Is PYC faster than py?

pyc files is faster than parsing the . py file using ANTLR.

What is the use of .PYC file in Python?

pyc file contains the “compiled bytecode” of the imported module/program so that the “translation” from source code to bytecode can be skipped on subsequent imports of the *. py file. Having a *. pyc file saves the compilation time of converting the python source code to byte code, every time the file is imported.


1 Answers

Compiled Python bytecode files are architecture-independent, but VM-dependent. A .pyc file will only work on a specific set of Python versions determined by the magic number stored in the file.

like image 56
Ignacio Vazquez-Abrams Avatar answered Sep 20 '22 09:09

Ignacio Vazquez-Abrams