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, inFile "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
文件。
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.py
那 helloKivy.spec
就被重置了。
然后,生成的 helloKivy.exe
就可以正常执行了。(在我的系统上这样做是成功的!)