Detailed Python and the file type generated using the so / pyd file

python file types

.py file

.Py extension to file is python code source file, you can directly see the code executed by the python interpreter.

.pyc

.Pyc extension to file is the code for the source file of compiled files.
Its execution speed is faster than py file.
Simple compiler, not encrypted, decompile can get the source code.

.pyw

.pyw file and its essence is a qualitative .pyc file.
The difference is that the implementation of the program will appear .pyc file GUI console, the GUI program execution point .pyw not appear console.

.pyo

"Python -O source" Python source code can be compiled into .pyo file, but sometimes still have to adopt .pyc suffix, to run properly.
.pyo file is relatively .pyc terms, optimizing Python file compiled.

.The / so

You may disassemble, but not decompile.
.pyd file a non-Python, "write - compile" generated by other programming languages Python extension modules.
Cython can be individual based on the Python language Python modules compiled into .pyd or so file with the C language features. Essentially converted to C code sub pyd / so file.

Generate so / pyd file

  • Installation easycython, currently supports only to python3.6. pypi address
    pip install easycython
  • The need to generate so / pyd files into pyx py file suffix.
    Such as: pay.pynamed:pay.pyx
  • Using a command easycython xxx.pyxautomatically generated pyd(windows)or so(linux).
  • Wherein the generated file name hello.cpython-36m-x86_64-linux-gnu.somiddle portion removed, such as hello.so.

选区012.png

Instructions

  • Main.py create a new file.
import os
import sys

#将当前so所在的路径添加到sys.path, python是在sys.path路径中找模块的
sys.path.append(os.path.realpath('.'))
from hello import hello 
hello()

选区013.png

pyd文件理论上也是一样的。

发布了60 篇原创文章 · 获赞 0 · 访问量 1412

Guess you like

Origin blog.csdn.net/ClassmateLin/article/details/100513015
Recommended