准备环境
- Python 3.x (建议x>=9);
- Anaconda;
- Pycharm IDE (建议)
基本操作方法
- 打开Pycharm界面
- 打开本地终端窗口
- 输入:
pip install pyinstaller(已安装则可跳过这一步) - 安装完成后,假设被执行的.py文件为’program.py’,则继续在终端界面输入:
pyinstaller --noconsole --onefile program.py
- 成功运行后,在相同文件目录内进入’dist’文件夹即可查询到program.exe
直接安装到同文件目录的方法
接上面的第3步之后:
输入:
pyinstaller --noconsole --onefile --distpath . program.py
为.exe创建图标的方法
- .py文件的同文件目录已存在图标的.ico文件,假设存在logo.ico
- (pyinstaller已安装后)在同文件目录的终端输入:
pyinstaller --onefile --noconsole --icon==logo.ico program.py
此时文件将保存到’dist’文件夹内,
或直接保存.exe文件至同文件目录:
pyinstaller --onefile --noconsole --icon==logo.ico --distpath . program.py
即可。

被折叠的 条评论
为什么被折叠?



