当前位置: 首页 > 后端技术 > Python

python文件打包为exe程序(pyinstaller)

时间:2023-03-26 12:26:40 Python

场景:.py文件需要脱离环境单独执行,一般用于将功能交给非开发人员使用。前提:安装pyinstaller:pipinstallpyinstaller手动安装upx,否则打包命令时有可能报错163INFO:UPXisnotavailable。seleniumpyinstalleronefile.exe安装方法进入https://github.com/upx/upx/re...找到对应的版本,比如win64,下载下来解压upx-4.0.0-win64.zip和把upx.exe和pyinstaller.py放在同一目录下例如:C:\Users\xxxxx\PycharmProjects\pythonProject\venv\Scripts\pyinstaller.exePackage.py脚本进入需要打包的py文件的目录,比如cdC:\Users\xxxx\PycharmProjects\pythonProject\demo1114然后pyinstaller-Frun.py或者把upx.exe放到你想放的路径下,以E盘为例pyinstaller-Frun.py--upx-dirE:\以上两种方法都可以。最后你会发现demo1114目录下有2个文件夹。dist中使用了exe程序。直接双击打开运行demo1114/run.pyimportrequestsimporturllib3if__name__=='__main__':words=input("请输入你的幸运数字")print(f"{words}是你的幸运数字")words=input(“按任何一个键退出”)