打包封装py程序为exe

# 安装打包程序
pip install pyinstaller
# 安装图片转换程序
pip install Pillow

安装自动图片转换程序是为了解决ico文件的自动转换问题

ValueError: Received icon image 'C:\Users\"你的账号"\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller\001.ico' which exists but is not in the correct format. On this platform, only ('exe', 'ico') images may be used as icons. If Pillow is installed, automatic conversion will be attempted. Please install Pillow or convert your 'ico' file to one of ('exe', 'ico') and try again.


一般情况下,你需要把jpg等文件“另存为”BMP位图,最后去重命名后缀为“*.ico”文件。

路径:“***********\Python\Python311\Lib\site-packages\PyInstaller\”,最后去重命名后缀为“*.ico”文件。


然后去这里cmd

C:\Users\"你的账号"\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyInstaller

执行打包命令:

# 打包为一个文件
pyinstaller -F -i 002.ico -c 111.py
# 打包为一个文件夹
pyinstaller -D -i 002.ico -c 111.py

-F 代表为一个文件

-D 代表为一个文件夹

-i 代表指定图标文件

-c 代表有命令行窗口

最后文件打包完成,出现在“***********\Python\Python311\Lib\site-packages\PyInstaller\dist”dist文件夹中

 

 

如果你是venv环境,应该如何封装呢? 你可以这样

从Pycharm中的

查找第三方库

再从中定位PyInstaller——打开于——资源管理器

然后我们就获取到了所有路径:

 

Copy这个路径,在你的Pycharm中 cd到这个路径,

执行打包命令

这样你就可以在你的venv环境中直接编译打包这个py文件为exe文件了

posted @ 2024-04-01 13:48  Magiclala  阅读(62)  评论(0编辑  收藏  举报