pyinstaller 将 python文件 打包成exe
kivydev64 v5.0打包说明
默认打包python3代码,python2没有测试,可以在buildozer.spec中修改。在项目目录下运行打包命令:
kdpp go
等同于
buildozer android debug
第一次打包使用kdpp go生成我修改过的spec文件,之后可以用buildozer命令,等价的。打包的代码如果包含jnius或者其他第三方库,请修改spec文件添加对应第三方库到requirement,再打包。
在打包一个项目后,要打包其他项目时,先运行清理环境命令:
kdpp clean
等同于
buildozer android clean
打包release apk:
kdpp release
等同于
buildozer android release
kivydev64 v2.0
打包环境下载地址 https://pan.baidu.com/s/1K5SRPxMX2iZIaMZcUWpt3w
Vbox4.3.12下载地址 https://pan.baidu.com/s/1c2Ol81E
vbox4.3.12 Extension pack下载地址 https://pan.baidu.com/s/1hsspuIC
系统 Ubuntu 16.04 64位
用户名 kivydev 密码 kivydev
用户名root 密码 root
已安装增强工具,支持共享文件夹、分辨率调整、宿主机与虚拟机复制粘贴
今天发布的虚拟机可以正常打包apk,并且支持target sdk version 26以上打包.各位在使用中遇到问题可以直接在issue提出,或者到kivy中国开发者群(群号:534622543)向我反馈。
在此,感谢一如既往帮助我,支持我的朋友、大佬们。
特别感谢校长大佬@linuxrootok
主机端设置(Windows)
-
修改config.json中
"inbounds"
下的"listen"
为"0.0.0.0"
,并修改config.json文件属性为只读,防止GUI修改该文件 -
v2.ray的UI中“参数设置”-“v2.rayN设置”-“允许来自局域网的连接”
-
防火墙设置:“设置”-“Windows安全中心”-“防火墙和网络保护”-“高级设置”-“入站规则”-“虚拟机监控(回显请求-ICMPv4/v6-in)”,防止虚拟机ping不通网关
-
使用
ipconfig
查看VMware Network Adapter VMnet8
的ip地址 -
配置代理
网卡设置为nat或者桥接,宿主代理打开接受局域网连接,记录ipconfig下的ipv4地址,和代理端口。在虚拟机运行下面命令,打开代理。
sudo gedit /etc/wgetrc
修改如下内容:
https_proxy = http://192.168.25.1:10808/
http_proxy = http://宿主ip:端口号/
ftp_proxy = http://宿主ip:端口号/
use_proxy = on
buildozer -v android debug
Python kivy打包apk笔记
https://blog.csdn.net/qq_43551034/article/details/104873485
一、打包exe文件所必须要使用的组件是pyinstaller文件,用pip install pyinstaller
安装即可。
C:\Python36>pip install pyinstaller Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting pyinstaller Using cached pyinstaller-4.2-py3-none-any.whl
二、app.py是项目的入口文件,定位到app.py的文件夹(c:/python/sg),在cmd里输入定位到主要入口python文件的地址,输入pyinstaller -F app.py
运行后,exe文件即打包成功。
C:\python\sgmp>pyinstaller -F app.py 69 INFO: PyInstaller: 4.2 4634 INFO: Building EXE because EXE-00.toc is non existent 4634 INFO: Building EXE from EXE-00.toc 4687 INFO: Copying icons from ['c:\\python36\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico'] 4742 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes 4742 INFO: Writing RT_ICON 1 resource with 3752 bytes 4813 INFO: Updating resource type 24 name 1 language 0 4815 INFO: Appending archive to EXE C:\python\sgmp\dist\app.exe 4826 INFO: Building EXE from EXE-00.toc completed successfully.
spec文件说明
buildozer打包依靠buildozer.spec配置参数。下面简要说明下主要参数:
[app] # (str) app应用名 title = My Application # (str) 包名结尾 package.name = myapp # (str) 包名开头,如果打包release apk必须把test改成其他任意字符串 package.domain = org.test # (str) main.py所在目录,默认是spec所在目录 source.dir = . # (list) 打包进apk的文件 source.include_exts = py,png,jpg,kv,atlas # (list) 打包进apk的文件 #source.include_patterns = assets/*,images/*.png # (list) 不打包进apk的文件 #source.exclude_exts = spec # (list) 不打包进apk的目录,默认是tests和bin #source.exclude_dirs = tests, bin # (list) 不打包进apk的文件 #source.exclude_patterns = license,images/*/*.jpg # (str) app版本 version = 0.1 # (str) Application versioning (method 2) # version.regex = __version__ = ['"](.*)['"] # version.filename = %(source.dir)s/main.py # (list) 通称 requirements,打包第三方库时必须添加到这里 # comma separated e.g. requirements = sqlite3,kivy requirements = python3,kivy # (str) 第三方库源代码所在目录,如果指定了,打包时就会直接使用这个源代码,不会再去下载。 # Sets custom source for any requirements with recipes # requirements.source.kivy = ../../kivy # (list) Garden requirements,如果你用到kivy.graden的库就需要添加到这里 #garden_requirements = # (str) app启动时的画面图片(闪屏)路径,默认是kivy图标 #presplash.filename = %(source.dir)s/data/presplash.png # (str) app图标路径 #icon.filename = %(source.dir)s/data/icon.png # (str) app显示方向,默认是竖屏 (one of landscape, sensorLandscape, portrait or all) orientation = portrait # (list) service服务列表 #services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY # # OSX Specific # # # author = © Copyright Info # change the major version of python used by the app osx.python_version = 3 # Kivy version to use osx.kivy_version = 1.9.1 # # Android specific # # (bool) app是否全屏,默认否 fullscreen = 0 # (string) 闪屏的背景色 # Supported formats are: #RRGGBB #AARRGGBB or one of the following names: # red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray, # darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy, # olive, purple, silver, teal. #android.presplash_color = #FFFFFF # (list) Permissions app权限配置 #android.permissions = INTERNET # (int) Target Android API, 目标api level android.api = 27 # (int) Minimum API ,app能支持的最低api level android.minapi = 21 # (int) Android SDK 版本 #android.sdk = 27 # (str) Android NDK 版本 android.ndk = 19c # (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi. android.ndk_api = 21 # (bool) Use --private data storage (True) or --dir public storage (False) #android.private_storage = True # (str) Android NDK 路径 android.ndk_path = /home/kivydev/andr/android-ndk-r19c # (str) Android SDK 路径 android.sdk_path = /home/kivydev/andr/android-sdk-linux # (str) ANT directory 路径 android.ant_path = /home/kivydev/andr/apache-ant-1.9.4 # (bool) 是否跳过Android sdk 升级,默认否 # android.skip_update = False # (bool) 升级sdk过程中会询问同意接受sdk license,默认是提示你选择,改为True则是默认同意接受 # android.accept_sdk_license = False # (str) app 入口类,一般不修改 #android.entrypoint = org.renpy.android.PythonActivity # (str) app主题类型,一般不修改 # android.apptheme = "@android:style/Theme.NoTitleBar" # (list) 白名单 #android.whitelist = # (str) 白名单文件路径 #android.whitelist_src = # (str) 黑名单文件路径 #android.blacklist_src = # (list) 自定义jar添加到这里,供jnius调用,支持通配符 # OUYA-ODK/libs/*.jar #android.add_jars = foo.jar,bar.jar,path/to/more/*.jar # (list) 自定义java文件添加到这里 #android.add_src = # (list) aar文件添加到这里 #android.add_aars = # (list) Gradle dependencies to add (currently works only with sdl2_gradle # bootstrap) #android.gradle_dependencies = # (list) add java compile options # this can for example be necessary when importing certain java libraries using the 'android.gradle_dependencies' option # see https://developer.android.com/studio/write/java8-support for further information # android.add_compile_options = "sourceCompatibility = 1.8", "targetCompatibility = 1.8" # (list) Gradle repositories to add {can be necessary for some android.gradle_dependencies} # please enclose in double quotes # e.g. android.gradle_repositories = "maven { url 'https://kotlin.bintray.com/ktor' }" #android.add_gradle_repositories = # (list) packaging options to add # see https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html # can be necessary to solve conflicts in gradle_dependencies # please enclose in double quotes # e.g. android.add_packaging_options = "exclude 'META-INF/common.kotlin_module'", "exclude 'META-INF/*.kotlin_module'" #android.add_gradle_repositories = # (list) 增加java activity到manifest #android.add_activites = com.example.ExampleActivity # (str) OUYA Console category. Should be one of GAME or APP # If you leave this blank, OUYA support will not be enabled #android.ouya.category = GAME # (str) Filename of OUYA Console icon. It must be a 732x412 png image. #android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png # (str) XML file to include as an intent filters in <activity> tag #android.manifest.intent_filters = # (str) launchMode to set for the main activity #android.manifest.launch_mode = standard # (list) Android additional libraries to copy into libs/armeabi #android.add_libs_armeabi = libs/android/*.so #android.add_libs_armeabi_v7a = libs/android-v7/*.so #android.add_libs_arm64_v8a = libs/android-v8/*.so #android.add_libs_x86 = libs/android-x86/*.so #android.add_libs_mips = libs/android-mips/*.so # (bool) Indicate whether the screen should stay on # Don't forget to add the WAKE_LOCK permission if you set this to True #android.wakelock = False # (list) Android application meta-data to set (key=value format) #android.meta_data = # (list) Android library project to add (will be added in the # project.properties automatically.) #android.library_references = # (list) Android shared libraries which will be added to AndroidManifest.xml using <uses-library> tag #android.uses_library = # (str) Android logcat filters to use #android.logcat_filters = *:S python:D # (bool) Copy library instead of making a libpymodules.so #android.copy_libs = 1 # (str) app架构,支持: armeabi-v7a, arm64-v8a, x86, x86_64 android.arch = armeabi-v7a # # Python for android (p4a) specific # # (str) python-for-android fork to use, defaults to upstream (kivy) #p4a.fork = kivy # (str) 使用的p4a分支 #p4a.branch = master # (str) p4a源代码路径,默认从网络下载 #p4a.source_dir = # (str) recipes路径 #p4a.local_recipes = # (str) Filename to the hook for p4a #p4a.hook = # (str) Bootstrap to use for android builds # p4a.bootstrap = sdl2 # (int) port number to specify an explicit --port= p4a argument (eg for bootstrap flask) #p4a.port = # # iOS specific # # (str) Path to a custom kivy-ios folder #ios.kivy_ios_dir = ../kivy-ios # Alternately, specify the URL and branch of a git checkout: ios.kivy_ios_url = https://github.com/kivy/kivy-ios ios.kivy_ios_branch = master # Another platform dependency: ios-deploy # Uncomment to use a custom checkout #ios.ios_deploy_dir = ../ios_deploy # Or specify URL and branch ios.ios_deploy_url = https://github.com/phonegap/ios-deploy ios.ios_deploy_branch = 1.7.0 # (str) Name of the certificate to use for signing the debug version # Get a list of available identities: buildozer ios list_identities #ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)" # (str) Name of the certificate to use for signing the release version #ios.codesign.release = %(ios.codesign.debug)s [buildozer] # (int) Log level (0 = error only, 1 = info, 2 = debug (with command output)) log_level = 2 # (int) Display warning if buildozer is run as root (0 = False, 1 = True) warn_on_root = 1 # (str) .buildozer文件路径 build_dir = /home/kivydev/test/.buildozer # (str) Path to build output (i.e. .apk, .ipa) storage # bin_dir = ./bin # ----------------------------------------------------------------------------- # List as sections # # You can define all the "list" as [section:key]. # Each line will be considered as a option to the list. # Let's take [app] / source.exclude_patterns. # Instead of doing: # #[app] #source.exclude_patterns = license,data/audio/*.wav,data/images/original/* # # This can be translated into: # #[app:source.exclude_patterns] #license #data/audio/*.wav #data/images/original/* # # ----------------------------------------------------------------------------- # Profiles # # You can extend section / key with a profile # For example, you want to deploy a demo version of your application without # HD content. You could first change the title to add "(demo)" in the name # and extend the excluded directories to remove the HD content. # #[app@demo] #title = My Application (demo) # #[app:source.exclude_patterns@demo] #images/hd/* # # Then, invoke the command line with the "demo" profile: # #buildozer --profile demo android debug
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix