日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

记:PyInstaller打包一个最简单的kivy应用

發(fā)布時(shí)間:2025/4/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 记:PyInstaller打包一个最简单的kivy应用 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

OS: windows 10
python: 2.7.6 64bit

在kivy官網(wǎng)有篇介紹打包kivy應(yīng)用的文章 傳送門(mén): Programming Guide ? Create a package for Windows
我照葫蘆畫(huà)瓢,原樣復(fù)制了代碼,和步驟!打包成功!但是運(yùn)行報(bào)錯(cuò)。

Traceback (most recent call last):File "site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 11, in <module>File "c:\users\wxg\appdata\local\temp\pip-build-px2be5\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_moduleFile "build\bdist.win-amd64\egg\pkg_resources\__init__.py", line 48, in <module>File "build\bdist.win-amd64\egg\pkg_resources\extern\__init__.py", line 60, in load_module ImportError: 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

沒(méi)six這個(gè)包。把ImportError: The 'six' package is required;作為關(guān)鍵字拿去搜索,最靠譜的一個(gè)答案是 stackoverflow 上的 Kivy - Create package on Windows
有人提到把 setuptools 的版本降低到 19.2 ,其實(shí)沒(méi)必要。
至少在我的系統(tǒng)上,我沒(méi)有降低版本,也成功了。我的是 19.6.2 如下:

C:\Users\wxg\PycharmProjects\untitled\demo\helloworld>pip list configparser (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)建立一個(gè) helloKivy.py 文件,如下:

import kivyfrom kivy.app import App from 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 所在的目錄下執(zhí)行如下命令:

pyinstaller helloKivy.py

這會(huì)生成 helloKivy.spec 文件。
(4)參考官網(wǎng)的介紹,修改這個(gè)文件
在文件頂部添加如下代碼:

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)],

改完后是這個(gè)樣子的:

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)然后并沒(méi)結(jié)束。在我的系統(tǒng)中還要添加上下面這段:

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

這些都是我們?cè)诘?2)步安裝的。 'packaging.version' 和 'packaging.specifiers'是屬于'packaging'的,必須寫(xiě)上。
完整的 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)現(xiàn)在再來(lái)執(zhí)行 pyinstaller helloKivy.spec 。注意是 helloKivy.spec ,如果你執(zhí)行 helloKivy.py 那 helloKivy.spec 就被重置了。

然后,生成的 helloKivy.exe 就可以正常執(zhí)行了。(在我的系統(tǒng)上這樣做是成功的!)

轉(zhuǎn)載于:https://my.oschina.net/juedui0769/blog/683722

總結(jié)

以上是生活随笔為你收集整理的记:PyInstaller打包一个最简单的kivy应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。