python_note
  • Introduction
  • My Python
    • Anaconda
    • argparse
    • datetime
    • json
    • logging
    • numpy
    • open
    • openCC
    • pandas & csv
    • Socket & SocketServer
    • re
    • yaml
    • smtp
    • 物件操作
    • unittest
    • 線程
    • prettytable
    • IO
    • pycurl
    • sys
    • pickle
    • auto-python-to-exe
    • cython
    • nuitka
  • Crawler
    • Urllib & Requests
      • User-agent
      • Percent-Encoding
      • mail code
    • Selenium
    • TCP & UDP
    • 控制字符(control character)
  • Web Development
    • Flask
      • RESTful api
      • Template
      • blueprint
    • Django
      • 環境佈署(windows)
    • 檢查Port
    • Apache
    • 使用者行為
    • jQuery
    • 壓力測試
    • DataTable
    • Bootstrap
    • CSS
    • JavaScript
    • Chart.js
  • Deep Learning
    • Keras 設定
    • RNN
    • LSTM
  • Test
    • T-Test
  • 資料結構
    • Hash
    • 時間複雜度
  • NLP
    • N-gram
    • CKIP
    • 中文轉數字
    • CRF
    • Mutual Information
    • 模糊比對
  • Linebot
    • Heroku
    • 圖文選單
    • channel
  • Linux
    • 常用指令
    • shell script
    • sshfs
    • ssh
    • nodejs & npm
    • debug
  • GCP
    • app engine
    • ssh(gcp)
    • gsutil
    • brabrabra
    • Load Balancer
    • k8s
  • Database
    • mysql
    • elasticsearch
      • Query
      • Backup and Restore
      • elasticdump
      • es2csv
      • ELK
    • mongodb
      • install
      • authentication
      • pymongo
    • sql server
  • go
    • Swarm
  • Docker
    • Kitematic
    • Dockerfile
    • Swarm
  • Git
  • 其他
    • USB軟體保護
    • Windows效能監視器
  • Blockchain
Powered by GitBook
On this page
  • auto-python-to-exe簡介
  • 測試情境
  • Issue
  • No module named 'win32com'
  • Failed to execute script pyi_rth_pkgres
  • No module named 'sklearn.utils._cython_blas'
  • jinja2.exceptions.TemplateNotFound
  • 套件名稱錯誤

Was this helpful?

  1. My Python

auto-python-to-exe

PreviouspickleNextcython

Last updated 5 years ago

Was this helpful?

auto-python-to-exe簡介

測試情境

將一個簡單的flask專案打包成exe

建議先使用anaconda建立虛擬環境,再依照其進行套件測試與打包

anaconda安裝完成後,在cmd執行:

conda create --name py37 python=3.7
source activate py37

進入py37後再開始使用pip install

添加version file

在--version-file添加此txt,StringTable內容可自行變更

# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
  ffi=FixedFileInfo(
    # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
    # Set not needed items to zero 0.
    filevers=(1, 0, 0, 0),
    prodvers=(1, 0, 0, 0),
    # Contains a bitmask that specifies the valid bits 'flags'r
    mask=0x3f,
    # Contains a bitmask that specifies the Boolean attributes of the file.
    flags=0x28,
    # The operating system for which this file was designed.
    # 0x4 - NT and there is no need to change it.
    OS=0x40004,
    # The general type of file.
    # 0x1 - the file is an application.
    fileType=0x2,
    # The function of the file.
    # 0x0 - the function is not defined for this fileType
    subtype=0x0,
    # Creation date and time stamp.
    date=(0, 0)
    ),
  kids=[
    StringFileInfo(
      [
      StringTable(
        u'000004b0',
        [StringStruct(u'FileVersion', u'1.1.2.2'),
        StringStruct(u'ProductVersion', u'1.1.1.1'),
        StringStruct(u'OriginalFilename', u'888'),
        StringStruct(u'InternalName', u'333'),
        StringStruct(u'FileDescription', u'555'),
        StringStruct(u'CompanyName', u'ITRI'),
        StringStruct(u'LegalCopyright', u'cITRIM100'),
        StringStruct(u'ProductName', u'666'),
        StringStruct(u'Comments', u'111'),
        StringStruct(u'LegalTrademarks', u'777'),
        StringStruct(u'SpecialBuild', u'444'),
        StringStruct(u'PrivateBuild', u'999')])
      ]), 
    VarFileInfo([VarStruct(u'Translation', [0, 1200])])
  ]
)

也可用下載輔助工具FVIE直接對exe做修改

參考文章:

Issue

No module named 'win32com'

執行auto-python-to-py時,可能會出現這個錯誤,不確定是否影響輸出結果保險起見也補上

pip install pypiwin32

Failed to execute script pyi_rth_pkgres

  1. 建議重新安裝最新版的pyinstaller

pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
  1. 如果更新pyinstaller一樣沒用,建議使用不一樣版本的setuptools (網路上大部分都嘗試降版)

pip uninstall setuptools
pip install setuptools==45.0.0

No module named 'sklearn.utils._cython_blas'

直接在--hidden-import新增sklearn.utils._cython_blas

jinja2.exceptions.TemplateNotFound

常見原因:

  1. template設定錯誤,導致找不到html

  2. 在cmd用相對路徑啟動exe,導致無法讀取到tamplate資料夾,如:

.\app_test app.exe
  1. 需在flask添加flask_bootstrap模組 (我沒遇到,參考用)

打包成功的環境配置:

windows 10 + python3.7(conda虛擬環境) + auto-py-to-exe=2.6.6 + setuptools=45.0.0 + PyInstaller=4.0.dev0+a1f92c6a08 (pip list就寫這摸醜) + pywin32=227

套件名稱錯誤

尚未確認,有待認證

有時候套件大小寫或特殊符號("-")有可能導致包裝時發出錯誤

如:flask-wtf。可替換成flask_wtf

http://markjong001.pixnet.net/blog/post/252910444-[%E7%B4%94%E5%88%86%E4%BA%AB4]-%E7%9C%9F%EF%BC%8Epy-to-csv-%E7%94%A8%22auto-py-to-exe%22-%E8%A7%A3%E6%B1%BA%22recu
https://pypi.org/project/auto-py-to-exe/
https://www.codelast.com/%E5%8E%9F%E5%88%9B-anaconda%E5%AE%89%E8%A3%85python-3-6%E7%89%88%E6%9C%AC/
https://www.itread01.com/content/1546701845.html
https://www.52pojie.cn/thread-783376-1-1.html
https://blog.csdn.net/weixin_41879093/article/details/104216881
https://github.com/pypa/setuptools/issues/1963
https://stackoverflow.com/questions/57108026/pyinstaller-modulenotfounderror-no-module-named-sklearn-utils-cython-blas
https://www.pythonanywhere.com/forums/topic/14019/
https://www.jianshu.com/p/8df0fbe4e64e