在編寫了python工具之后原押,為了方便在windows下使用胁镐,會將文件打包成exe。下面介紹打包的一些知識。
安裝環(huán)境
# 安裝打包庫
pip install pyinstaller
# 更新打包庫
pip install --upgrade pyinstaller
- 嘗試過在3.6版本下盯漂,使用了這兩個指令颇玷,打包的文件還是會出現(xiàn)這樣的問題:
config> .\export_excel.exe
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 13, in <module>
File "c:\users\abel\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pkg_resources\__init__.py", line 86, in <module>
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
原因還是來自于下載的版本太陳舊造成。3.6版本的python下運行需要安裝最新的版本就缆。
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
你也可以從GitHub里面下載最新的版本帖渠。
https://github.com/pyinstaller/pyinstaller/tarball/develop
這段文字是官方網(wǎng)站的原文:
The latest stable release of PyInstaller is 3.6 (Change Log).
Release 3.6: stable, supports Python 2.7, 3.5–3.7
PyInstaller 3.6 (tar.gz) (pgp, sha-256: 3730fa80d088f8bb7084d32480eb87cbb4ddb64123363763cf8f2a1378c1c4b7)
Development: unstable, supports Python 3.5–3.7
Current development code (tar.gz)
Current development code (zip)
If you want to motify the source, you may better clone the git repository using git clone https://github.com/pyinstaller/pyinstaller and may want to refer to the Development Guide in the manual.
Older (obsolete) releases can be found at the full list of releases.
打包流程
基本指令:
pyinstaller [options] script [script …] | specfile
現(xiàn)在我編寫的工具是console,所以需要使用這個選項
Windows and Mac OS X specific options
-c, --console, --nowindowed
Open a console window for standard i/o (default). On Windows this option will have no effect if the first script is a ‘.pyw’ file.
更加詳細的信息竭宰,可以查閱空郊,引用部分,使用手冊