【发布时间】:2019-11-08 14:32:54
【问题描述】:
环境:
Windows 10
蟒蛇 3.6.6
cx-冻结 5.0.2
Git hub example
它包含.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.exe-
lib\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 可以很容易地转换为原始文件(没有 cmets),例如python-uncompyle6.
详情:
(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.pyc
3) (用this question 解决)在这两点上:文件包含源路径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 级别:) 但是对于大项目来说它看起来很奇怪。
【问题讨论】:
-
从documentation,
cx_freeze不支持构建单个文件的exe。 -
@HenryYik 是的,我已经读过,但是如果我将所有文件都放在
main.py级别-它将包含在.exe中:) 因此我认为有一些方便的方法可以对所有文件执行相同操作。 -
您自己的话:“此时我只看到我的方式:将所有文件放在
main.py级别”也反映了我对您的问题的看法。 -
关于您的观点 3)“应用程序 [...] 不应该知道源目录(关于路径)”:也许 this answer 中描述的 cx_Freeze 选项
replace_paths可以帮助您解决这一点? -
@jpeg yeap :) 它有助于#3
标签: python python-3.x pyinstaller cx-freeze decompiling