使用 py2exe 创建单文件可执行文件
Create a single-file executable using py2exe
我写了一个 python 代码,它使用 Tkinter 显示 window。
它还会调用同一文件夹中的另一个 python 文件。
我使用 py2exe 将 .py 文件转换为 .exe 文件。但我面临以下问题:
输出(在 dist 文件夹中)是一组文件,而不是单个可执行文件。
- 根据我对
'bundle_files':1,'compressed':True
的理解,我应该得到一个文件。
- 现在我有两个 .exe 文件和 1 个文件夹:w9xpopen.exe、myframe.py(这是我的文件)和文件夹“tcl"
图标未更改。
- 我在 "windows" 部分提到了
"icon_resources":[(0,"icon.ico")]
下面是我用的setup.py:
from distutils.core import setup
import py2exe, glob,sys,os
sys.argv.append('py2exe')
setup(
options={'py2exe':{'bundle_files':1,'compressed':True}},
windows=[{"script":'hr_data_downloader.py',"icon_resources": [(0,"icon.ico")]}],
data_files = [],
zipfile=None
)
起初我遇到了问题 运行 可执行文件,但在浏览了以下帖子后,我通过显式添加两个 dll 来更正它。
Creating single EXE using py2exe for a Tkinter program
py2exe - generate single executable file
如果可以通过修改安装文件或任何其他 py2exe 文件来创建单文件可执行文件,请告诉我。
另外请告诉我为什么没有为创建的.exe显示图标
如果 py2exe 可以帮助我创建单文件可执行文件,我愿意尝试其他分发实用程序。
我想出了如何使用 pyinistaller 来完成它。
虽然它使 exe 相当大,但我很高兴我只有一个文件。
下面是我所做的:
- 已安装pyinstaller,pywin32
- 打开命令提示符
- 转到我的代码文件夹
- 使用命令
pyinstaller --onefile --windowed myframe.py
pyinstaller的手册有详细的解释。
Pyinstaller 可用于从 python 项目生成单个可执行文件。
第 1 步:
安装 Pyinstaller
https://www.pyinstaller.org/downloads.html
https://github.com/pyinstaller/pyinstaller/zipball/develop
第 2 步:
将文件解压到 python 安装目录 (C:\Python27\)
将提取的文件夹重新命名为:pyinstaller
第 3 步:
现在在 Python 目录和
中打开命令提示符
use command : cd pyinstaller
(创建exe)
use command : python pyinstaller.py your_python_file.py
(创建单个 exe)
use command : python pyinstaller.py --onefile --windowed your_python_file.py
(your_python_file.py : 应该放在C:\Python27\pyinstaller\)
输出文件夹:C:\Python27\pyinstaller\main\dist
我写了一个 python 代码,它使用 Tkinter 显示 window。 它还会调用同一文件夹中的另一个 python 文件。 我使用 py2exe 将 .py 文件转换为 .exe 文件。但我面临以下问题:
输出(在 dist 文件夹中)是一组文件,而不是单个可执行文件。
- 根据我对
'bundle_files':1,'compressed':True
的理解,我应该得到一个文件。 - 现在我有两个 .exe 文件和 1 个文件夹:w9xpopen.exe、myframe.py(这是我的文件)和文件夹“tcl"
- 根据我对
图标未更改。
- 我在 "windows" 部分提到了
"icon_resources":[(0,"icon.ico")]
- 我在 "windows" 部分提到了
下面是我用的setup.py:
from distutils.core import setup
import py2exe, glob,sys,os
sys.argv.append('py2exe')
setup(
options={'py2exe':{'bundle_files':1,'compressed':True}},
windows=[{"script":'hr_data_downloader.py',"icon_resources": [(0,"icon.ico")]}],
data_files = [],
zipfile=None
)
起初我遇到了问题 运行 可执行文件,但在浏览了以下帖子后,我通过显式添加两个 dll 来更正它。
Creating single EXE using py2exe for a Tkinter program
py2exe - generate single executable file
如果可以通过修改安装文件或任何其他 py2exe 文件来创建单文件可执行文件,请告诉我。 另外请告诉我为什么没有为创建的.exe显示图标
如果 py2exe 可以帮助我创建单文件可执行文件,我愿意尝试其他分发实用程序。
我想出了如何使用 pyinistaller 来完成它。 虽然它使 exe 相当大,但我很高兴我只有一个文件。
下面是我所做的:
- 已安装pyinstaller,pywin32
- 打开命令提示符
- 转到我的代码文件夹
- 使用命令
pyinstaller --onefile --windowed myframe.py
pyinstaller的手册有详细的解释。
Pyinstaller 可用于从 python 项目生成单个可执行文件。
第 1 步:
安装 Pyinstaller
https://www.pyinstaller.org/downloads.html
https://github.com/pyinstaller/pyinstaller/zipball/develop
第 2 步:
将文件解压到 python 安装目录 (C:\Python27\)
将提取的文件夹重新命名为:pyinstaller
第 3 步:
现在在 Python 目录和
中打开命令提示符
use command : cd pyinstaller
(创建exe)
use command : python pyinstaller.py your_python_file.py
(创建单个 exe)
use command : python pyinstaller.py --onefile --windowed your_python_file.py
(your_python_file.py : 应该放在C:\Python27\pyinstaller\)
输出文件夹:C:\Python27\pyinstaller\main\dist