我可以使用自定义模块文件和其他文件创建单个exe吗?

时间:2013-10-22 10:24:34

标签: python-2.7

现在我正在用python开发一个中等项目。

它有许多模块,其中一些是自定义模块。其中一些是非python文件(可能是配置文件),需要使用如复制/粘贴(例如当客户端运行此应用程序并插入一些hw设备时,应用程序将配置hw设备并复制某些应用程序文件到hw设备(可能是ROM))

首先我的问题是:我可以用我的所有代码,模块和非python文件创建1个单独的exe吗?

如果是,我该怎么办?

2 个答案:

答案 0 :(得分:1)

您可以尝试更改方法并将所有文件作为文本放入模块中。 那么你可以使用py2exe来创建可执行文件,它将包含你需要的所有数据。只有当你有一些小文件时,这种方法才有意义。

如果您想嵌入更多更大的文件,请查看该解决方案: Py2exe: Embed static files in exe file itself and access them

答案 1 :(得分:0)

  1. 打开CMD
  2. 更改PyInstaller目录的路径。(ex-C:\ PyInstaller-2.1)
  3. 使用此命令

    pyinstaller.py my.py --noconsole --onefile --icon=icon.ico

  4. 将my.py更改为您的脚本名称。

    --noconsole option remove the python console while executing your program. If you need console to get an output,just remove --noconsole
    --onefile option makes all the modules and files in to one executable file.
    --icon=icon.ico gives your exe an icon.Remember to put your icon file in Pyinstaller directory