在编写了python工具之后,为了方便在windows下使用,会将文件打包成exe。下面介绍打包的一些知识。
安装环境
# 安装打包库
pip install pyinstaller
# 更新打包库
pip install --upgrade pyinstaller
- 尝试过在3.6版本下,使用了这两个指令,打包的文件还是会出现这样的问题:
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
这段文字是官方网站的原文:
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
现在我编写的工具是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.
更加详细的信息,可以查阅,引用部分,使用手册