title: python-使用pyinstaller打包成可执行程序
categories: Python
tags: [python, pyinstaller]
date: 2020-05-14 17:22:56
comments: false
mathjax: true
toc: true
python-使用pyinstaller打包成可执行程序. 这里使用的是 Python3.6
前篇
- 【Python】使用 PyInstaller 將 Python打包成 exe 檔 - https://medium.com/pyladies-taiwan/python-%E5%B0%87python%E6%89%93%E5%8C%85%E6%88%90exe%E6%AA%94-32a4bacbe351
流程
-
安装 pyinstaller
$ pip3 install pyinstaller
-
打包. 命令:
pyinstaller -F xxx.py
e:\its_rummy\tools (rls-money-7324 -> origin) $ pyinstaller -F tinypng_win.py 70 INFO: PyInstaller: 3.6 71 INFO: Python: 3.6.5 ... 8750 INFO: Appending archive to EXE e:\its_rummy\tools\dist\tinypng_win.exe 9086 INFO: Building EXE from EXE-00.toc completed successfully.
会生成 build 和 dist 两个目录, 可执行程序在 dist 目录下.
pyinstaller 常用参数介绍
- -h : 查看参数
- -F : 打包成一个 exe 文件
- –icon : icon 图片
- -w : 使用视窗, 无控制台
- -c : 使用控制台, 无视窗
- -D : 创建一个目录, 包含 exe 以及其他一些依赖性文件
踩坑
找不到 tls 证书
报错: Could not find a suitable TLS CA certificate bundle
解决办法: 从 Python 安装目录下找到 Lib\site-packages\certifi\cacert.pem
, 复制到程序能读到的地方
代码中加入:
os.environ['REQUESTS_CA_BUNDLE'] = os.path.join(SelfPath, 'cacert.pem') # cacert.pem 路径
重新打包即可.
参考: https://blog.csdn.net/qq_40770527/article/details/104847046