Coder Social home page Coder Social logo

colinsongf / py2sec Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cckuailong/py2sec

0.0 1.0 0.0 222 KB

:snake: py2sec is a Cross-Platform, Fast and Flexible tool to change the .py to .so(Linux and Mac) or .pyd(Win).

License: MIT License

Python 100.00%

py2sec's Introduction

py2sec

English Readme

py2sec 一款轻量的脚本工具,基于 Cython 将 .py 编译成 run-time libraries 文件:.so (Linux && Mac),或 .pyd (Win)。一定程度上实现了“加密”保护源代码的需求。

系统支持

Linux && MacOS && Windows

注意:Windows用户运行时可能会遇到如下错误

error: command 'cl.exe' failed: No such file or directory

请安装对应Win系统版本的Visual C++ Build Tools

py2sec 特性

  1. .so / .pyd 文件可以像 .py 模块一样正常调用。例如:importfrom module import * "
  2. py2sec 可以指定编译单个 .py 文件,也可以指定一个 python 项目目录
  3. py2sec 还可以提升代码运行速度,至多提升30倍
  4. py2sec 自动识别项目中的 .py 文件,且只编译 .py 类型文件
  5. 可以指定不需要编译的文件或子目录
  6. py2sec 不影响源文件,加密后的文件或项目将被存放在 result 文件夹
  7. 兼容多平台:macOS、Linux、Windows、
  8. 兼容 Python 版本:python2 and python3, 可使用 -p(--py) 参数来指定版本
  9. 支持多线程(待改进)

环境配置

pip install requirements.txt

使用说明

使用

请将要加密的目录或文件存放在py2sec根目录下

python py2sec.py [选项] ...

选项

-v,  --version    显示 py2sec 版本
-h,  --help       显示帮助菜单
-p,  --pyth       Python的版本, 默认为 你的 "python" 命令绑定的python版本
                  例: -p 3  (比如你使用python3)
-d,  --directory  Python项目路径 (如果使用-d参数, 将编译整个Python项目)
-f,  --file       Python文件 (如果使用-f, 将编译单个Python文件)
-m,  --maintain   标记你不想编译的文件或文件夹路径
                  注意: 文件夹需要以路径分隔符号(`/`或`\\`,依据系统而定)结尾,并且需要和-d参数一起使用 
                  例: -m setup.py,mod/__init__.py,exclude_dir/
-x  --nthread     编译启用的线程数
-q  --quiet       静默模式,默认False
-r  --release     Release 模式,清除所有中间文件,只保留加密结果文件,默认False
python py2sec.py -f test.py
python py2sec.py -f example/test1.py -r
python py2sec.py -d example/ -m test1.py,bbb/

# 一些操作系统使用 "python3" 命令来执行python3,如Ubuntu,这里可以使用 -p 参数来运行
python3 py2sec.py -p 3 -d example/

项目结构

  • build/ 临时文件夹, .o, .so/.pyd 文件
  • tmp_build/ 临时文件夹, .c 文件
  • result/ 编译最终结果存放目录
  • result/log.txt 编译过程日志
  • py2sec.py 主函数文件
  • py2sec_build.py.template 用于生成 py2sec_build.py 的模板文件
  • requirements.txt 依赖库的清单

协议

本项目遵循MIT协议

示例

整个Python项目编译前:

demo1

py2sec 编译后效果:

demo2

py2sec's People

Contributors

cckuailong avatar nodewee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.