Python 基维:如何使用应用程序文件夹中的文本文件?
创建了一个程序。使用文本文件存储设置,该文件与main.py启动文件一起位于程序的根文件夹中。编译小程序后,程序将停止查看文本文件。在这样做的过程中,我将txt文件添加到推土机规范文件中。我使用内置命令找到程序目录: 自我目录 错误日志:Python 基维:如何使用应用程序文件夹中的文本文件?,python,kivy,Python,Kivy,创建了一个程序。使用文本文件存储设置,该文件与main.py启动文件一起位于程序的根文件夹中。编译小程序后,程序将停止查看文本文件。在这样做的过程中,我将txt文件添加到推土机规范文件中。我使用内置命令找到程序目录: 自我目录 错误日志: adb logcat | grep python 10-03 13:53:48.114 4043 4072 I python : Initializing Python for Android 10-03 13:53:48.11
adb logcat | grep python
10-03 13:53:48.114 4043 4072 I python : Initializing Python for Android
10-03 13:53:48.114 4043 4072 I python : Setting additional env vars from p4a_env_vars.txt
10-03 13:53:48.114 4043 4072 I python : Changing directory to the one provided by ANDROID_ARGUMENT
10-03 13:53:48.114 4043 4072 I python : /data/user/0/org.trade.tradeprog_py3/files/app
10-03 13:53:48.114 4043 4072 I python : Preparing to initialize python
10-03 13:53:48.114 4043 4072 I python : _python_bundle dir exists
10-03 13:53:48.114 4043 4072 I python : calculated paths to be...
10-03 13:53:48.114 4043 4072 I python : /data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/stdlib.zip:/data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/modules
10-03 13:53:48.115 4043 4072 I python : set wchar paths...
10-03 13:53:48.211 4043 4072 I python : Initialized python
10-03 13:53:48.211 4043 4072 I python : AND: Init threads
10-03 13:53:48.213 4043 4072 I python : testing python print redirection
10-03 13:53:48.216 4043 4072 I python : Android path ['.', '/data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/modules', '/data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/site-packages']
10-03 13:53:48.217 4043 4072 I python : os.environ is environ({'PATH': '/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/system/vendor/bin:/vendor/xbin:/system/vendor/xbin:/product/bin:/product/xbin', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'BOOTCLASSPATH': '/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/hwEmui.jar:/system/framework/hwTelephony-common.jar:/system/framework/hwframework.jar:/system/framework/org.simalliance.openmobileapi.jar:/system/framework/org.ifaa.android.manager.jar:/system/framework/hwaps.jar:/system/framework/hwcustEmui.jar:/system/framework/hwcustTelephony-common.jar:/system/framework/hwcustframework.jar:/system/framework/servicehost.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/hwServices.jar:/system/framework/hwWifi-service.jar:/system/framework/hwcustServices.jar:/system/framework/hwcustwifi-service.jar', 'OEM_ROOT': '/hw_oem', 'CUST_POLICY_DIRS': '/system/emui/base:/system/emui/oversea:/system/emui/lite:/system/global:/vendor/etc:/product/etc:/hw_oem:/cust/hw/normal:/cust/hw/eu:/data/cust:/version/region_comm/oversea:/cust_spec', 'ANDROID_SOCKET_zygote_secondary': '14', 'ANDROID_ENTRYPOINT': 'main.pyc', 'ANDROID_ARGUMENT': '/data/user/0/org.trade.tradeprog_py3/files/app', 'ANDROID_APP_PATH': '/data/user/0/org.trade.tradeprog_py3/files/app', 'ANDROID_PRIVATE': '/data/user/0/org.trade.tradeprog_py3/files', 'ANDROID_UNPACK': '/data/user/0/org.trade.tradeprog_py3/files/app', 'PYTHONHOME': '/data/user/0/org.trade.tradeprog_py3/files/app', 'PYTHONPATH': '/data/user/0/org.trade.tradeprog_py3/files/app:/data/user/0/org.trade.tradeprog_py3/files/app/lib', 'PYTHONOPTIMIZE': '2', 'P4A_BOOTSTRAP': 'SDL2', 'PYTHON_NAME': 'python', 'P4A_IS_WINDOWED': 'False', 'P4A_ORIENTATION': 'portrait', 'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
10-03 13:53:48.217 4043 4072 I python : Android kivy bootstrap done. __name__ is __main__
10-03 13:53:48.217 4043 4072 I python : AND: Ran string
10-03 13:53:48.217 4043 4072 I python : Run user program, change dir and execute entrypoint
10-03 13:53:48.538 4043 4072 I python : [WARNING] [Config ] Older configuration version detected (0 instead of 21)
10-03 13:53:48.539 4043 4072 I python : [WARNING] [Config ] Upgrading configuration in progress.
10-03 13:53:48.550 4043 4072 I python : [INFO ] [Logger ] Record log in /data/user/0/org.trade.tradeprog_py3/files/app/.kivy/logs/kivy_19-10-03_0.txt
10-03 13:53:48.550 4043 4072 I python : [INFO ] [Kivy ] v1.11.1
10-03 13:53:48.551 4043 4072 I python : [INFO ] [Kivy ] Installed at "/data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/site-packages/kivy/__init__.pyc"
10-03 13:53:48.551 4043 4072 I python : [INFO ] [Python ] v3.7.1 (default, Oct 3 2019, 13:25:41)
10-03 13:53:48.551 4043 4072 I python : [Clang 6.0.2 (https://android.googlesource.com/toolchain/clang 183abd29fc496f55
10-03 13:53:48.552 4043 4072 I python : [INFO ] [Python ] Interpreter at "android_python"
10-03 13:53:49.833 4043 4072 I python : [INFO ] [Factory ] 184 symbols loaded
10-03 13:53:50.618 4043 4072 I python : [INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
10-03 13:53:50.704 4043 4072 I python : [INFO ] [Text ] Provider: sdl2
10-03 13:53:50.814 4043 4072 I python : [INFO ] [Window ] Provider: sdl2
10-03 13:53:50.954 4043 4072 I python : [INFO ] [GL ] Using the "OpenGL ES 2" graphics system
10-03 13:53:50.957 4043 4072 I python : [INFO ] [GL ] Backend used <sdl2>
10-03 13:53:50.958 4043 4072 I python : [INFO ] [GL ] OpenGL version <b'OpenGL ES 3.0 V@145.0 AU@07.01.01.269.023 (GIT@Ib1167d03fb)'>
10-03 13:53:50.959 4043 4072 I python : [INFO ] [GL ] OpenGL vendor <b'Qualcomm'>
10-03 13:53:50.960 4043 4072 I python : [INFO ] [GL ] OpenGL renderer <b'Adreno (TM) 308'>
10-03 13:53:50.961 4043 4072 I python : [INFO ] [GL ] OpenGL parsed version: 3, 0
10-03 13:53:50.976 4043 4072 I python : [INFO ] [GL ] Texture max size <4096>
10-03 13:53:50.976 4043 4072 I python : [INFO ] [GL ] Texture max units <16>
10-03 13:53:51.035 4043 4072 I python : [INFO ] [Window ] auto add sdl2 input provider
10-03 13:53:51.037 4043 4072 I python : [INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
10-03 13:53:51.216 4043 4072 I python : [INFO ] [__init__ ] system info: uname_result(system='Linux', node='localhost', release='3.18.31-g9d6a405', version='#2 SMP PREEMPT Fri Nov 2 10:10:17 CST 2018', machine='armv8l', processor='')
10-03 13:53:51.217 4043 4072 I python : [INFO ] [__init__ ] Program directory: .
10-03 13:53:51.218 4043 4072 I python : папки программы ['p4a_env_vars.txt', 'main.pyc', '_python_bundle', '.nomedia', 'private.version', '.kivy', 'crash.log']
10-03 13:53:51.221 4043 4072 I python : Traceback (most recent call last):
10-03 13:53:51.222 4043 4072 I python : File "/tmp/tmps4qipl07/main.py", line 2112, in <module>
10-03 13:53:51.224 4043 4072 I python : File "/home/TERRA/PythonExp/kivy_exp/TRADE_v3-1_py3/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/TradeProg_py3/kivy/app.py", line 829, in run
10-03 13:53:51.225 4043 4072 I python : File "/tmp/tmps4qipl07/main.py", line 2082, in build
10-03 13:53:51.226 4043 4072 I python : File "/tmp/tmps4qipl07/main.py", line 319, in __init__
10-03 13:53:51.227 4043 4072 I python : FileNotFoundError: [Errno 2] No such file or directory: './settings.txt'
10-03 13:53:51.228 4043 4072 I python : Python for android ended.
adb logcat | grep python
10-03 13:53:48.114 4043 4072 I python:为Android初始化python
10-03 13:53:48.114 4043 4072 I python:从p4a_env_vars.txt设置其他环境变量
10-03 13:53:48.114 4043 4072 I python:将目录更改为ANDROID_参数提供的目录
10-03 13:53:48.114 4043 4072 I python:/data/user/0/org.trade.tradeprog_py3/files/app
10-03 13:53:48.114 4043 4072 I python:准备初始化python
10-03 13:53:48.114 4043 4072 I python:_python_bundle dir存在
10-03 13:53:48.114 4043 4072 I python:计算的路径将。。。
10-03 13:53:48.114 4043 4072 I python:/data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/stdlib.zip:/data/user/0/org.trade.tradeprog_py3/files/app//python_bundle/modules
10-03 13:53:48.115 4043 4072 I python:设置wchar路径。。。
10-03 13:53:48.211 4043 4072 I python:已初始化python
10-03 13:53:48.211 4043 4072 I python:和:初始化线程
10-03 13:53:48.213 4043 4072 I python:测试python打印重定向
10-03 13:53:48.216 4043 4072 I python:Android路径['.','/data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/stdlib.zip','/data/user/0/org.trade.tradeprog_py3/files/app/_python_bundle/modules','/data/user/0/org.trade.trade.trade.python_py3/files/app/_bundle/site packages']
10-03 13:53:48.217 4043 4072 I python:os.environ是environ({'PATH':'/sbin:/vendor/bin:/system/sbin:/system/bin:/system/vendor/bin:/vendor/xbin:/system/vendor/xbin:/product/bin:/product/xbin','ANDROID\u BOOTLOGO':'1','ANDROID\u ROOT':'/system/system','ANDROID\u资产':'/system/app','ANDROID\u数据':'/DATA','ANDROID\u存储':'/STORAGE','EXTERNAL存储':','EXTERNAL存储':'sdcard','ASEC\u挂载点':'/mnt/ASEC',BOOTCLASSPATH':'/system/framework/core oj.jar:/system/framework/core libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core junit.jar:/system/framework/ext.jar:/system/framework/telephony common.jar:/system/framework/voip common.jar:/system/frameworkem/framework/ims common.jar:/system/framework/apache xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/hwEmui.jar:/system/framework/hwframework.jar:/system/framework/org.simalliance.openmobileapi.jar:/system/framework/org.ifaa.android.manager.jar:/system/framework/hwaps.jar:/system/framework/hwcustEmui.jar:/system/framework/hwcustTelephony common.jar:/system/framework/hwcustframework.jar:/system/framework/services.jar','SYSTEMSERVERCLASSPATH':'/system/framework/ethernet service.jar:/system/framework/wifi service.jar:/system/framework/hwServices.jar:/system/framework/hwWifi/service.jar:/system/framework/hwcustServices.jar:/system/framework/hwcustwifi service.jar',OEM_ROOT':'/hw_OEM',CUST_POLICY_DIRS':'/system/emui/overseas:/system/emui/lite:/system/global:/vendor/etc:/product/etc:/hw_OEM:/CUST/hw/normal:/CUST/hw/eu:/data/CUST:/version/region_comm/overseas:/CUST:/CUST\u spec','ANDROID_SOCKET\u zytte\u secondary':'14','ANDROID_ENTRYPOINT':'main.pyc','ANDROID_ARGUMENT':'/data/user/0/org.trade.tradeprog_py3/files/app','ANDROID_路径':'/data/user/0/org.trade.tradeprog_路径':'/data/user/0/org.trade.tradeprog_py3/files','ANDROID_解包':'/data/user/0/org.trade.tradeprog_py3/files/app','py3','PYTHONHOME'/data/user/trade.trade.orgprog_py3/files/app',PYTHONPATH':'/data/user/0/org.trade.tradeprog_py3/files/app:/data/user/0/org.trade.tradeprog_py3/files/app/lib',PYTHONOPTIMIZE':'2',P4A_引导程序':'SDL2',PYTHON_名称':'PYTHON',P4A_窗口化':'False',P4A_方向':'P4A方向':'纵向','P4A(数字版':'None','P4A)dka(minsu LC版本':'21',cUTU类型:'C-8})
10-03 13:53:48.217 4043 4072 I python:Android kivy引导程序已完成。uuu name_uuuuuuu是uuuu main__
10-03 13:53:48.217 4043 4072 I python:AND:Ran字符串
10-03 13:53:48.217 4043 4072 I python:运行用户程序,更改目录并执行入口点
10-03 13:53:48.538 4043 4072 I python:[警告][配置]检测到较旧的配置版本(0而不是21)
10-03 13:53:48.539 4043 4072 I python:[警告][配置]正在升级配置。
10-03 13:53:48.550 4043 4072 I python:[INFO][Logger]记录登录/data/user/0/org.trade.tradeprog_py3/files/app/.kivy/logs/kivy_19-10-03_0.txt
10-03 13:53:48.550 4043 4072 I python:[INFO][Kivy]v1.11.1
10-03 13:53:48.551 4043 4072 I python:[INFO][Kivy]安装在“/data/user/0/org.trade.tradeprog\u py3/files/app/\u python\u bundle/site packages/Kivy/\u init\u.pyc”
10-03 13:53:48.551 4043 4072 I python:[INFO][python]v3.7.1(默认值,2019年10月3日,13:25:41)
10-03 13:53:48.551 4043 4072 I巨蟒:[叮当声6.0.2(https://android.googlesource.com/toolchain/clang 183abd29fc496f55
10-03 13:53:48.552 4043 4072 I python:[信息][python]解释器位于“android_python”
10-03 13:53:49.833 4043 4072 I python:[信息][工厂]加载了184个符号
10-03 13:53:50.618 4043 4072 I python:[信息][图像]提供程序:img_-tex、img_-dds、img_-sdl2、img_-gif(img_-pil、img_-ffpyplayer忽略)
10-03 13:53:50.704 4043 4072 I python:[信息][文本]提供程序:sdl2
10-03 13:53:50.814 4043 4072 I python:[信息][窗口]
[app]
# (str) Title of your application
title = TradeProg_py3
# (str) Package name
package.name = TradeProg_py3
# (str) Package domain (needed for android/ios packaging)
package.domain = org.trade
# (str) Source code where the main.py live
source.dir = .
# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,txt
# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png
# (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec
# (list) List of directory to exclude (let empty to not exclude anything)
source.exclude_dirs = plyer
# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg
# (str) Application versioning (method 1)
version = 3.2
# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
# version.filename = %(source.dir)s/main.py
# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = plyer, sqlite3,python3, kivy
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
# requirements.source.kivy = ../../kivy
# (list) Garden requirements
#garden_requirements =
# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png
# (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png
# (str) Supported orientation (one of landscape, portrait or all)
orientation = portrait
# (list) List of service to declare
#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 = 2.7
# Kivy version to use
#osx.kivy_version = 1.10.1
#
# Android specific
#
# (bool) Indicate if the application should be fullscreen or not
fullscreen = 1
# (string) Presplash background color (for new android toolchain)
# 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
android.permissions = WRITE_EXTERNAL_STORAGE, WAKE_LOCK,READ_EXTERNAL_STORAGE,ACCESS_CHECKIN_PROPERTIES
# (int) Android API to use
android.api = 26
# (int) Minimum API required
#android.minapi = 17
# (int) Android SDK version to use
#android.sdk = 22
# (str) Android NDK version to use
android.ndk = 17c
# (bool) Use --private data storage (True) or --dir public storage (False)
#android.private_storage = True
# (str) Android NDK directory (if empty, it will be automatically downloaded.)
android.ndk_path = /home/TERRA/Android/android-ndk-r17c
# (str) Android SDK directory (if empty, it will be automatically downloaded.)
#android.sdk_path = /home/TERRA/android-studio
# (str) ANT directory (if empty, it will be automatically downloaded.)
#android.ant_path = /home/TERRA/Android/apache-ant-1.10.5
# (bool) If True, then skip trying to update the Android sdk
# This can be useful to avoid excess Internet downloads or save time
# when an update is due and you just want to test/build your package
# android.skip_update = False
# (str) Android entry point, default is ok for Kivy-based app
#android.entrypoint = org.renpy.android.PythonActivity
# (list) Pattern to whitelist for the whole project
#android.whitelist =
# (str) Path to a custom whitelist file
#android.whitelist_src =
# (str) Path to a custom blacklist file
#android.blacklist_src =
# (list) List of Java .jar files to add to the libs so that pyjnius can access
# their classes. Don't add jars that you do not need, since extra jars can slow
# down the build process. Allows wildcards matching, for example:
# OUYA-ODK/libs/*.jar
#android.add_jars = foo.jar,bar.jar,path/to/more/*.jar
# (list) List of Java files to add to the android project (can be java or a
# directory containing the files)
#android.add_src =
# (list) Android AAR archives to add (currently works only with sdl2_gradle
# bootstrap)
#android.add_aars =
# (list) Gradle dependencies to add (currently works only with sdl2_gradle
# bootstrap)
#android.gradle_dependencies =
# (list) Java classes to add as activities to the manifest.
#android.add_activites = com.example.ExampleActivity
# (str) python-for-android branch to use, defaults to stable
#p4a.branch = stable
# (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 additionnal 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_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 =
# (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) The Android arch to build for, choices: armeabi-v7a, arm64-v8a, x86
#android.arch = armeabi-v7a
#
# Python for android (p4a) specific
#
# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
#p4a.source_dir =
# (str) The directory in which python-for-android should look for your own build recipes (if any)
#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
# (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) Path to build artifact storage, absolute or relative to spec file
# build_dir = ./.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