1.需求

为了保证线上代码安全和效率,使用python编写代码,pyc可直接反编译,于是把重要代码编译so文件

2.工作

2.1 安装相关库:

pip install cython
yum install -y gcc python-devel

2.2 创建setup.py

#!/usr/bin/env python
# coding=utf-8
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("xxxx.py")
)

2.3 运行

root@868aec72d1a4:/xxx/xxx/xxx# python setup.py build_ext
Compiling xxx.py because it changed.
[1/1] Cythonizing xxx.py
running build_ext
building 'lib.xxx' extension
creating build
creating build/temp.linux-x86_64-2.7
x86_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.o
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/lib
x86_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

会在当年目录上传build目录,结构如下:

root@868aec72d1a4:/spider/codes/lib# tree build/
build/
|-- lib.linux-x86_64-2.7
| `-- lib
| `-- xxx.so
`-- temp.linux-x86_64-2.7
`-- xxx.o 3 directories, 2 files

2.4 获取so文件即可

最新文章

  1. js中 javascript:void(0) 用法详解
  2. AOP 手动,半自动,全自动
  3. backup3
  4. ReactJS学习笔记(三)
  5. Android简化xml sax解析
  6. Spring Boot+AngularJS中因为跨域导致Session丢失
  7. Oracle用户、权限、角色管理
  8. .NET MVC4 实训记录之七(实现资源的自主访问后续)
  9. zf-关于把某个地址的svn项目移动到另一个上面的步骤
  10. spring注解一次 清除多个缓存
  11. 魔术常量(Magic constants)
  12. Esptouch移植xamarin记要
  13. Java作业一 (2017-9-10)
  14. 浏览器对象模型BOM总结
  15. Codeforces Round #290 (Div. 2) E. Fox And Dinner 网络流建模
  16. urllib模块学习
  17. linux命令学习之:systemctl
  18. [Umbraco] 自定义DataType中Data Editor Setting Type
  19. Python 3.6 安装pip
  20. php判断是否为时间戳

热门文章

  1. Variation calling and annotation
  2. PAT1021. Deepest Root (25)
  3. Flume-NG源码阅读之HDFSEventSink
  4. 语音02_Delphi
  5. 重写ddt的mk_test_name方法
  6. 找到Office 2016 for MAC中AutoUpdate等组件的本地下载位置
  7. 51nod 1686 二分+离散化
  8. 24 Python 对象进阶
  9. 20 Python 常用模块
  10. mysql分表和分区实际应用简介