python-使用pyinstaller打包成可執行程序


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

流程

  1. 安裝 pyinstaller

    $ pip3 install pyinstaller
    
  2. 打包. 命令: 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.
    

    會生成 builddist 兩個目錄, 可執行程序在 dist 目錄下.


pyinstaller 常用參數介紹

  1. -h : 查看參數
  2. -F : 打包成一個 exe 文件
  3. –icon : icon 圖片
  4. -w : 使用視窗, 無控制檯
  5. -c : 使用控制檯, 無視窗
  6. -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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章