TypeError: must be str, not bytes
See original GitHub issueVersions
- Python: 3.5.3 (running in virtualenv and in root) (seems to be running Python 3.7.1 on Android based on the logs)
- OS: Ubuntu 17:04
- Kivy: 1.9.1
- Cython: 0.28.6
- Andoid 7.0 (on Samsung Galaxy S6)
Description
I have compiled a very basic helloWorld app as below. The app works fine on Ubuntu and also compiles fine into apk using buildozer.
__version__ = '1.0'
from kivy.app import App
from kivy.uix.button import Button
class Hello(App):
def build(self):
btn = Button(text='Hello World')
return btn
Hello().run()
When I run on Android the app immediately closes before displaying the hello world screen. After working through logs produced with adb logcat I see the following…
06-25 19:48:52.272 2100 2118 I python : Traceback (most recent call last):
06-25 19:48:52.272 2100 2118 I python : File "/home/lee/KivyProjects/helloWorld/.buildozer/android/app/main.py", line 3, in <module>
06-25 19:48:52.273 2100 2118 I python : File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/kivy/app.py", line 319, in <module>
06-25 19:48:52.273 2100 2118 I python : File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/kivy/base.py", line 26, in <module>
06-25 19:48:52.274 2100 2118 I python : File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/kivy/clock.py", line 410, in <module>
06-25 19:48:52.274 2100 2118 I python : File "<frozen importlib._bootstrap>", line 983, in _find_and_load
06-25 19:48:52.274 2100 2118 I python : File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
06-25 19:48:52.275 2100 2118 I python : File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
06-25 19:48:52.275 2100 2118 I python : File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
06-25 19:48:52.276 2100 2118 I python : File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/ctypes/util.py", line 73, in <module>
06-25 19:48:52.276 2100 2118 I python : File "/home/lee/KivyProjects/helloWorld/.buildozer/android/platform/build/build/python-installs/helloWorld/android/__init__.py", line 8, in <module>
06-25 19:48:52.277 2100 2118 I python : File "android/_android.pyx", line 162, in init android._android
06-25 19:48:52.277 2100 2118 I python : TypeError: must be str, not bytes
06-25 19:48:52.277 2100 2118 I python : Python for android ended.
This appears to be the same issue raised as 1691 under the title “unicode error during startup (python3, numpy, opencv) - patch included #1691”. If I am reading this patch correctly the current file _android.pyx should have the following changes
removed this line python_act = autoclass(JAVA_NAMESPACE + u’.PythonActivity’)
added these lines java_namespace = JAVA_NAMESPACE.decode() if isinstance(JAVA_NAMESPACE, bytes) else JAVA_NAMESPACE python_act = autoclass(java_namespace + u’.PythonActivity’)
Yet when I look at the current code on Github for _android.pyx I do not see these changes applied. Has this fix somehow been removed from the current version? How can i apply this fix to my system?
Issue Analytics
- State:
- Created 4 years ago
- Comments:31 (2 by maintainers)
Top GitHub Comments
I just looked at the code in pythonforandroid/build.py and it seems to me this is a bug, it uses “Cython” as a binary rather than using sys.executable/python2/python3 -m cython which should probably fix this. I’ll see if I can change that, it seems fixable to me
@synccodes did you try
sudo pip uninstall cython
,pip uninstall cython
(to make sure it’s gone from all places) and thensudo pip3 install cython
? If it’s really cython being installed via python 2 that should possibly fix it