-
安装pywin32,可以参考《怎么给python安装pywin32模块?》
一定要注意对应的python版本,否则不能安装。
5怎么给python安装pywin32模块? 安装网站 :https://github.com/mhammond/pywin32/releases
-
用命令行调用pip安装pyinstaller。
-
准备一个py文件。
我这里准备的是一个爬取电子书的python文件——00.py。
-
准备一个图片,作为exe的图标:
b.ico
注意图片格式是ico的,大小为32*32,不要太大。没有的话,可以在网上免费转格式。
把00.py和b.ico放到一个目录里面——C:\a
-
把cmd的当前目录切换到C:\a。
-
然后执行命令行:
pyinstaller -F -i b.ico 00.py
-
运行之后,cmd变成了这样。
-
在C:\a目录里面,多出了几个文件夹。
可执行文件00.exe就在dist文件夹里面。
-
双击可执行文件,会弹出一个命令提示符端口,提示你输入书号。
按照格式输入书号,点击回车键,就可以在dist文件夹里面,看到一章章的电子书被下载下来了。
(1)遇到的错误:(https://www.cnblogs.com/jkn1234/p/9672957.html)
用pyinstaller打包python程序,解决打包时的错误:Cannot find existing PyQt5 plugin directories
- 将自己的python程序打包成.exe/.app(秀同学一脸呐) https://blog.youkuaiyun.com/MrLevo520/article/details/51840217
- Python程序打包成exe可执行文件 https://blog.youkuaiyun.com/zengxiantao1994/article/details/76578421
- 注意将要打包的py文件拷贝到新建的文件夹内
- 在打包时会出现问题Cannot find existing PyQt5 plugin directories ,具体截图如下
- 解决方法就是用everything搜索PyQt5,找到 /Library/plugins路径下的PyQt5文件夹,将里面的dll动态库pyqt5qmlplugin.dll复制出来
- 按照错误提示的路径,一个个的新建文件夹,形成目录C:\qt5b\qt_1524647842210\_h_env\Library\plugins,将刚才复制出来的dll动态库拷贝进去即可
(2)遇到的错误
pyinstaller WARNING: lib not found: xxxx.dll dependency of xxxxx 错误
背景
因为之前用pip 安装的PySIde2,而这种方式安装的PySide2只有源码缺少缺少lib库。所以用pyinstaller打包时会包报没发现lib。
12662 WARNING: lib not found: shiboken2.dll dependency of D:\Python\JDReminding\venv\lib\site-packages\PySide2\QtGui.p
yd
12871 WARNING: lib not found: shiboken2.dll dependency of D:\Python\JDReminding\venv\lib\site-packages\PySide2\QtWidge
ts.pyd
13026 WARNING: lib not found: shiboken2.dll dependency of D:\Python\JDReminding\venv\lib\site-packages\PySide2\QtCore.
pyd
13143 WARNING: lib not found: shiboken2.dll dependency of D:\Python\JDReminding\venv\lib\site-packages\PySide2\QtNetwo
rk.pyd
14200 WARNING: lib not found: shiboken2.dll dependency of D:\Python\JDReminding\venv\lib\site-packages\PySide2\pyside2
.dll
解决方法
用–paths 告诉pyinstaller去哪找到特定的库:
pyinstaller --paths D:\Python\JDReminding\venv\Lib\site-packages\shiboken2 hello.py