博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
记:PyInstaller打包一个最简单的kivy应用
阅读量:7303 次
发布时间:2019-06-30

本文共 3695 字,大约阅读时间需要 12 分钟。

hot3.png

OS: windows 10

python: 2.7.6 64bit

在kivy官网有篇介绍打包kivy应用的文章 传送门:

我照葫芦画瓢,原样复制了代码,和步骤!打包成功!但是运行报错。

Traceback (most recent call last):  File "site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 11, in 
File "c:\users\wxg\appdata\local\temp\pip-build-px2be5\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module File "build\bdist.win-amd64\egg\pkg_resources\__init__.py", line 48, in
File "build\bdist.win-amd64\egg\pkg_resources\extern\__init__.py", line 60, in load_moduleImportError: The 'six' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.Failed to execute script pyi_rth_pkgres

six这个包。把ImportError: The 'six' package is required;作为关键字拿去搜索,最靠谱的一个答案是 stackoverflow 上的

有人提到把 setuptools 的版本降低到 19.2 ,其实没必要。
至少在我的系统上,我没有降低版本,也成功了。我的是 19.6.2 如下:

C:\Users\wxg\PycharmProjects\untitled\demo\helloworld>pip listconfigparser (3.5.0)docutils (0.12)future (0.15.2)Kivy (1.9.1)Kivy-Garden (0.1.4)kivy.deps.glew (0.1.4)kivy.deps.sdl2 (0.1.12)packaging (16.7)pefile (2016.3.28)pip (8.1.2)Pygments (2.1.3)PyInstaller (3.2)pyparsing (2.1.4)pypiwin32 (219)requests (2.10.0)setuptools (19.6.2)six (1.10.0)wheel (0.29.0)

完整的描述下吧:

(1)建立一个 helloKivy.py 文件,如下:

import kivyfrom kivy.app import Appfrom kivy.uix.label import Labelclass MyApp(App):    def build(self):        return Label(text='Hello World')if __name__ == '__main__':    MyApp().run()

(2)安装一些必要的包,如下:

pip install pyinstaller six packaging configparser

(3)在 helloKivy.py 所在的目录下执行如下命令:

pyinstaller helloKivy.py

这会生成 helloKivy.spec 文件。

(4)参考官网的,修改这个文件
在文件顶部添加如下代码:

from kivy.deps import sdl2, glew

然后是修改 coll , 添加

Tree('C:\\Users\\wxg\\PycharmProjects\\untitled\\demo\\helloworld\\'),*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],

改完后是这个样子的:

coll = COLLECT(exe, Tree('C:\\Users\\wxg\\PycharmProjects\\untitled\\demo\\helloworld\\'),               a.binaries,               a.zipfiles,               a.datas,               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],               strip=False,               upx=True,               name='helloKivy')

(5)然后并没结束。在我的系统中还要添加上下面这段:

hiddenimports=['six','packaging','packaging.version','packaging.specifiers','configparser'],

这些都是我们在第(2)步安装的。 'packaging.version' 和 'packaging.specifiers'是属于'packaging'的,必须写上。

完整的 helloKivy.spec 样貌就是这样子的:

# -*- mode: python -*-from kivy.deps import sdl2, glewblock_cipher = Nonea = Analysis(['helloKivy.py'],             pathex=['C:\\Users\\wxg\\PycharmProjects\\untitled\\demo\\helloworld'],             binaries=None,             datas=None,             hiddenimports=['six','packaging','packaging.version','packaging.specifiers','configparser'],             hookspath=[],             runtime_hooks=[],             excludes=[],             win_no_prefer_redirects=False,             win_private_assemblies=False,             cipher=block_cipher)pyz = PYZ(a.pure, a.zipped_data,             cipher=block_cipher)exe = EXE(pyz,          a.scripts,          exclude_binaries=True,          name='helloKivy',          debug=False,          strip=False,          upx=True,          console=True )coll = COLLECT(exe, Tree('C:\\Users\\wxg\\PycharmProjects\\untitled\\demo\\helloworld\\'),               a.binaries,               a.zipfiles,               a.datas,               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],               strip=False,               upx=True,               name='helloKivy')

(6)现在再来执行 pyinstaller helloKivy.spec 。注意是 helloKivy.spec ,如果你执行 helloKivy.pyhelloKivy.spec 就被重置了。

然后,生成的 helloKivy.exe 就可以正常执行了。(在我的系统上这样做是成功的!)

转载于:https://my.oschina.net/juedui0769/blog/683722

你可能感兴趣的文章
linux 三剑客老三-grep
查看>>
win7 使用emeidter后无法右键新建记事本
查看>>
SaltStack之sls文件
查看>>
简单搭建LNMP平台
查看>>
记《浪潮之巅》-第一版-6.IT业的罗马帝国--微软,Microsoft
查看>>
苏州市相城区漕湖人民医院虚拟化容灾系统一套
查看>>
Powershell 之收集服务器配置
查看>>
【在线研讨】《敏捷开发用户故事分类与组织结构(三期-3)》
查看>>
16Python标准系列之random模块
查看>>
apache Options Directive 详解
查看>>
微信的视频如何找到文件并发送到电脑
查看>>
洛谷——P2421 A-B数对(增强版)
查看>>
洛谷——P1690 贪婪的Copy
查看>>
虚拟机vmx打不开Failed to lock the file的解决方法
查看>>
linux配置java环境变量
查看>>
Eclipse用4个空格代替tab
查看>>
我和linux的第七天
查看>>
删除msconfig系统配置下无效启动项
查看>>
Linux下如何简单删除/data的空目录
查看>>
让bat文件后台运行
查看>>