本文所有教程及源码、软件仅为技术钻研。不波及计算机信息零碎性能的删除、批改、减少、烦扰,更不会影响计算机信息零碎的失常运行。不得将代码用于非法用处,如侵立删!


应用jmpy模块 将py文件加密为so或pyd

操作环境

  • win10 、 mac
  • Python3.9
  • jmpy1.0.6

jmpy官网介绍

简介

将python代码一键加密为so或pyd。反对单个文件加密,整个我的项目加密。

Git仓库地址: https://github.com/Boris-code/jmpy.git

装置

pip install jmpy3

应用办法

jmpy -i "xxx project dir" [-o output dir]

加密后的文件默认存储在 dist/project_name/ 下

打包应用

jmpy 加密模块

# -*- coding: utf-8 -*-"""py文件加密为so或pydpython代码 加密|加固参数阐明:    -i | --input_file_path    待加密文件或文件夹门路,可是相对路径或绝对路径    -o | --output_file_path   加密后的文件输入门路,默认在input_file_path下创立dist文件夹,寄存加密后的文件    -I | --ignore_files       不须要加密的文件或文件夹,逗号分隔    -m | --except_main_file   不加密蕴含__main__的文件(主文件加密后无奈启动), 值为0、1。 默认为1报错:    AttributeError: 'str' object has no attribute 'decode'    找到报错文件:_msvccompiler.py    参考:https://blog.csdn.net/qq_43192819/article/details/108981008    128行代码批改为:.encode().decode('utf-16le', errors='replace')"""from jmpy.encrypt_py import start_encrypt# 须要加密的py文件input_file_path = "test.py"# 间接运行start_encrypt(input_file_path=input_file_path, output_file_path=None, ignore_files=None, except_main_file=0)

报错解决:AttributeError: ‘str’ object has no attribute 'decode’

首次应用时碰到了一个:AttributeError: 'str' object has no attribute 'decode'的报错
起因:Python2和Python3在字符串编码上的区别。
解决办法:先encode()转为字节码在进行解码

    找到报错文件:_msvccompiler.py参考:https://blog.csdn.net/qq_43192819/article/details/108981008128行代码批改为:.encode().decode('utf-16le', errors='replace')

资源下载

https://download.csdn.net/download/qq_38154948/85629166


本文仅供学习交换应用,如侵立删!
**