注:安装版本是有要求的。
Works out-of-the-box with any Python version 2.7 / 3.4-3.7.
安装:pip install pyinstaller
pypi地址: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
-dist
dist中只有一个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
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。