将python程序打包成exe文件的方法
-
将pip版本升级到>=10.0.0(可用pip -V 查看当前版本)
然后执行如下代码设置清华源:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple -
安装pyinstaller:
pip install pyinstaller -
打包命令:
(1) 普通方法: pyinstaller -F script.py
pyinstaller -F -w script.py (无视窗,程序后台运行)
(2) 当引用requests或bs4的时候需用如下命令打包,否则会缺少库文件。
pyinstaller -F --hidden-import queue script.py