描述
我正在尝试使用 buildozer (在 colab 中)将我的 Python 代码转换为
.apk
应用程序,但出现错误(我在错误末尾提供了我的代码)。
版本
错误:
Exception in thread background thread for pid 178998:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
...
return self.command.handle_command_exit_code(exit_code)
File "/root/.local/lib/python3.10/site-packages/sh.py", line 869, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /usr/bin/python3 '-cimport sys; from Cython.Compiler.Main import setuptools_main; sys.exit(setuptools_main());' ./kivy/core/image/_img_sdl2.pyx
STDOUT:
/usr/local/lib/python3.10/dist-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/kivy/armeabi-v7a__ndk_target_21/kivy/kivy/core/image/_img_sdl2.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
warning: kivy/core/image/../../lib/../include/config.pxi:2:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
...
warning: kivy/core/image/../../lib/sdl2.pxi:1073:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
Error compiling Cython file:
------------------------------------------------------------
...
# works only for write.
cdef SDL_RWops *rwops = SDL_AllocRW()
rwops.hidden.unknown.data1 = <void *>byteio
rwops.seek = NULL
rwops.read = NULL
rwops.write = &rwops_bytesio_write
^
------------------------------------------------------------
kivy/core/image/_img_sdl2.pyx:35:18: Cannot assign type 'size_t (*)(SDL_RWops *, const void *, size_t, size_t) except? -1' to 'size_t (*)(SDL_RWops *, void *, size_t, size_t) noexcept'
Error compiling Cython file:
------------------------------------------------------------
...
cdef SDL_RWops *rwops = SDL_AllocRW()
rwops.hidden.unknown.data1 = <void *>byteio
rwops.seek = NULL
rwops.read = NULL
rwops.write = &rwops_bytesio_write
rwops.close =&rwops_bytesio_close
^
------------------------------------------------------------
kivy/core/image/_img_sdl2.pyx:36:17: Cannot assign type 'int (*)(SDL_RWops *) except? -1' to 'int (*)(SDL_RWops *) noexcept'
STDERR:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1312, in <module>
main()
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
ToolchainCL()
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 734, in __init__
getattr(self, command)(args)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 153, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 212, in build_dist_from_args
build_recipes(build_order, python_modules, ctx,
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 504, in build_recipes
recipe.build_arch(arch)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 1031, in build_arch
self.build_cython_components(arch)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 1056, in build_cython_components
self.cythonize_build(env=env)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipes/kivy/__init__.py", line 38, in cythonize_build
super().cythonize_build(env, build_dir=build_dir)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 1104, in cythonize_build
self.cythonize_file(env, build_dir, join(root, filename))
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipes/kivy/__init__.py", line 59, in cythonize_file
super().cythonize_file(env, build_dir, filename)
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 1093, in cythonize_file
shprint(python_command, "-c"
File "/content/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 167, in shprint
for line in output:
File "/root/.local/lib/python3.10/site-packages/sh.py", line 915, in next
self.wait()
File "/root/.local/lib/python3.10/site-packages/sh.py", line 845, in wait
self.handle_command_exit_code(exit_code)
File "/root/.local/lib/python3.10/site-packages/sh.py", line 869, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /usr/bin/python3 '-cimport sys; from Cython.Compiler.Main import setuptools_main; sys.exit(setuptools_main());' ./kivy/core/image/_img_sdl2.pyx
STDOUT:
/usr/local/lib/python3.10/dist-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /content/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/kivy/armeabi-v7a__ndk_target_21/kivy/kivy/core/image/_img_sdl2.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
warning: kivy/core/image/../../lib/../include/config.pxi:2:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
...
warning: kivy/core/image/../../lib/sdl2.pxi:1073:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
Error compiling Cython file:
------------------------------------------------------------
...
# works only for write.
cdef SDL_RWops *rwops = SDL_AllocRW()
rwops.hidden.unknown.data1 = <void *>byteio
rwops.seek = NULL
rwops.read = NULL
rwops.write = &rwops_bytesio_write
^
------------------------------------------------------------
kivy/core/image/_img_sdl2.pyx:35:18: Cannot assign type 'size_t (*)(SDL_RWops *, const void *, size_t, size_t) except? -1' to 'size_t (*)(SDL_RWops *, void *, size_t, size_t) noexcept'
Error compiling Cython file:
------------------------------------------------------------
...
cdef SDL_RWops *rwops = SDL_AllocRW()
rwops.hidden.unknown.data1 = <void *>byteio
rwops.seek = NULL
rwops.read = NULL
rwops.write = &rwops_bytesio_write
rwops.close =&rwops_bytesio_close
^
------------------------------------------------------------
kivy/core/image/_img_sdl2.pyx:36:17: Cannot assign type 'int (*)(SDL_RWops *) except? -1' to 'int (*)(SDL_RWops *) noexcept'
这是我的代码:
import kivy
import socket
import threading
import rsa
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import mainthread
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
public_key, privet_key= rsa.newkeys(1024)
class MyRoot(BoxLayout):
server_public_key=None
def __init__(self):
super(MyRoot, self).__init__()
@mainthread
def update_chat_text(self, message):
self.chat_text.text += message + "\n"
def send_message(self):
client.send(rsa.encrypt(f"{self.nickname_text.text}: {self.message_text.text}".encode(), self.server_public_key))
def connect_to_server(self):
if self.nickname_text.text != "":
client.connect((self.ip_text.text, 9999))
message = client.recv(1024).decode('utf-8')
if message == "NICK":
client.send(self.nickname_text.text.encode('utf-8'))
self.server_public_key=rsa.PublicKey.load_pkcs1(client.recv(1024))
client.send(public_key.save_pkcs1('PEM'))
self.send_btn.disabled = False
self.message_text.disabled = False
self.connect_btn.disabled = True
self.ip_text.disabled = True
self.make_invisible(self.connection_grid)
self.make_invisible(self.connect_btn)
thread = threading.Thread(target=self.receive)
thread.start()
def make_invisible(self, widget):
widget.visible = False
widget.size_hint_x = None
widget.size_hint_y = None
widget.height = 0
widget.width = 0
widget.text = ""
widget.opacity = 0
def receive(self):
stop = False
while not stop:
try:
message = rsa.decrypt(client.recv(1024), privet_key).decode()
self.update_chat_text(message)
except Exception as ex:
print("ERROR:", ex)
client.close()
stop = True
class NeuralWebChat(App):
def build(self):
return MyRoot()
neuralWebChat = NeuralWebChat()
neuralWebChat.run()
我是 kivy 和编码新手,我很困惑