环境规划署:
Windows 10
python 3.6.6
cx-冻结5.0.2
它为安装.msi提供了条件
项目结构实例:
/package_name
/some_packet
/__init.py
/module_name.py # for an example contains valiable in code "module_1"
/main.py
/setup.py
/some_module.py # for an example contains valiable "module_2"
/some_other_module.py # for an example contains valiable "module_3"Setup.py示例(简化)
import cx_Freeze
cx_Freeze.setup(
name="example",
options={
"build_exe": {
"packages": ["asyncio"],
"include_files": ["static\some_static_file.png"]
},
"bdist_msi": {
"upgrade_code": "{492de237-1853-4599-a707-c283d567699f}"
}
},
executables=[cx_Freeze.Executable("main.py")]
)当前行为
用于创建.msi安装文件->运行命令python setup.py bdist_msi。它将生成用于安装应用程序的.msi文件。
安装此应用程序后:目录(安装应用程序的位置)将包含:
main.exelib\some_packet目录lib\some_packet\module_name.pyc文件有以下语句:
1)从根目录(安装了应用程序的地方)开始搜索(通过Ubuntu来宾系统下的grep -Rna命令,这对我来说更方便),可以在目录中找到可验证的module_1 (在lib\some_packet\module_name.pyc中),也找不到module_2/module_3。
详细信息:
(v_decompile) any@any-pc:/mnt/hgfs/shar/example_installed$ grep -Rna "module_1"
lib/some_packet/module_name.pyc:2:B�!]�@dZdS)module_1N)r�rr�PG:\heroes\installer-with-cx_Freeze\sources_of_project\some_packet\module_name.py<module>s
(v_decompile) any@any-pc:/mnt/hgfs/shar/example_installed$ grep -Rna -a "module_2"
(v_decompile) any@any-pc:/mnt/hgfs/shar/example_installed$ grep -Rna -a "module_3"2)文件lib\some_packet\module_name.pyc可以通过python-uncompyle6 6轻松地转换为原始文件(没有注释)。
详细信息:
(v_decompile) any@any-pc:/mnt/hgfs/shar/example_installed$ uncompyle6 lib/some_packet/module_name.pyc
# uncompyle6 version 3.3.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.6 (default, Jul 20 2018, 15:39:05)
# [GCC 4.8.4]
# Embedded file name: G:\heroes\installer-with-cx_Freeze\sources_of_project\some_packet\module_name.py
# Compiled at: 2019-07-07 11:28:50
module_1 = 'module_1'
# okay decompiling lib/some_packet/module_name.pyc3) (用这个问题解决)在这两点上:文件包含源路径G:\heroes\installer-with-cx_Freeze\sources_of_project\some_packet\module_name.py,这让我有点困惑。应用程序是从.msi安装的,(据我所知)不应该知道源目录(关于路径),它是用来创建最后一个目录的。
问题:
some_module.py和some_other_module.py恢复到main.exe的原始文件(就像用lib\some_packet\module_name.pyc做的那样)?main.exe中,或者如何避免将.pyc转换为原始文件(可能是cx_Freeze中的一些属性?)注意:
它应该用cx_Freeze来完成。
PS:我不想创建一个.exe。我试图找到方便的方法来指定哪些文件应该存储在main.exe中,就像用some_module.py和some_other_module.py所做的那样。
PSS:此时此刻,我只看到了我的方式:将所有文件放在main.py级别上:),但是对于大型项目来说,这看起来很奇怪。
发布于 2019-07-08 07:12:21
这两种使用pyobfuscate和分发字节码的方法实际上只是一种威慑,而不是隐藏代码的安全方法。 如果您想要更健壮的东西,应该看看努特卡,它将Python代码编译成C++,这样您就可以编译它并分发可执行文件。它似乎与不同库和不同版本的Python广泛兼容。
发布于 2019-07-15 21:50:25
这个视频可能会有帮助。它讨论了cxfreeze以及如何使用cx拟合来实现可执行性,我知道它适用于3.4+,因为视频使用python3.4,但实际上您的方法应该很好……
发布于 2019-07-16 18:24:42
如果我正确理解你的问题,这可能就是你想要的答案- 冻结两个或多个python文件(模块)
https://stackoverflow.com/questions/56776307
复制相似问题