安装

注:安装版本是有要求的。

Works out-of-the-box with any Python version 2.7 / 3.4-3.7.

安装:pip install pyinstallerpypi地址:https://pypi.org/project/PyInstaller/官网文档:https://pyinstaller.readthedocs.io/en/stable/打包

总共试了两种方法。都是按照官网操作的。

方式一:

打开cmd窗口,到主文件目录文件下,运行:pyinstaller mainscript.py在脚本同级目录下会生成了两个文件夹。-build-dist在dist中有个.exe文件,双击就可以执行了。可以把dist文件夹单独拿出来,build不知道做什么用,其中的exe文件与dist中的相同,但是双击后会出现闪退。如果项目下有配置文件需要加载,要把需要的配置文件放入到同exe一级的目录下。方式二:

打开cmd窗口,到主文件目录文件下,运行:pyinstaller --onefile --windowed myscript.py还是两个文件夹。-build-distdist中只有一个exe文件,但是无法打开。提示:Failed to execute script XXX。报错出错一:

在安装pyinstaller模块包的时候报了一次错误。
AttributeError: module 'enum' has no attribute 'IntFlag'

解决:卸载了enum34模块pip uninstall enum34出错二:

在堆wxpython程序封装的时候,出了一次错误。
AttributeError: 'str' object has no attribute 'items'

解决:pip install -U --pre setuptools