1. Requirements
In order to ensure the security and efficiency of online code, using Python to write code, PYC can be directly decompile, so the important code compiled so file
2. Work
2.1 Install the relevant library:
-Y gcc Python-devel
2.2 Creating setup.py
# !/usr/bin/env python # Coding=utf-8 from Import Setup from Import Cythonizesetup ( = cythonize ("xxxx.py"))
2.3 Run
[Email protected]:/xxx/xxx/xxx#python setup.py build_extcompiling xxx.py because it changed. [1/1] cythonizing xxx.pyrunning build_extbuilding'lib.xxx'extensioncreating buildcreating Build/temp.linux-x86_64-2.7x86_64-linux-gnu-gcc-pthread-dndebug-g-fwrapv-o2-wall-wstrict-prototypes-fno-strict-aliasing-wdate-time-d_fortify_ Source=2-g-fstack-protector-strong-wformat-werror=format-security-fpic-i/usr/include/python2.7-c Xxx.c-o build/ temp.linux-x86_64-2.7/xxx.ocreating Build/lib.linux-x86_64-2.7Creating Build/lib.linux-x86_64-2.7/libx86_64-LINUX-GNU-GCC-PTHREAD-SHARED-WL,-O1-WL,-BSYMBOLIC-FUNCTIONS-WL,-BSYMBOLIC-FUNCTIONS-WL,-Z,RELRO- Fno-strict-aliasing-dndebug-g-fwrapv-o2-wall-wstrict-prototypes-wdate-time-d_fortify_source=2-g- Fstack-protector-strong-wformat-werror=format-security-wl,-bsymbolic-functions-wl,-z,relro-wdate-time-d_ Fortify_source=2-g-fstack-protector-strong-wformat-werror=format-security Build/temp.linux-x86_64-2.7/xxx.o-o Build/lib.linux-x86_64-2.7/lib/xxx.so
The build directory will be uploaded in the current directory, with the following structure:
[Email protected]:/spider/codes/lib# tree build/build/|--lib.linux-x86_64-2.7| '-- lib| '-- xxx.so '--temp.linux-x86_64-2.7 '-- XXX.O3 directories, 2 files
2.4 Get so file
Use Cython to compile Python so