-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: must be str, not bytes #1885
Comments
Yes it looks like your are outdated. You seem to be using buildozer. Can you share the |
Thanks. The current code on Github seems outdated to me...as the patch mentioned in 1691 doesnt seem to be applied. I expect that is feeding the pip and apt repos.
|
I am also facing the same issue. What he said is correct. The patch isn't applied in the master branch. Please update it |
I think we fixed this differently, with JAVA_NAMESPACE now defined in I can't see anything in that buildozer config pointing at the latest develop version of p4a, maybe that is hte issue? I'm not sure if it's fixed in the latest stable release of p4a already, maybe @AndreMiras knows |
Ok.... so I will explain. I did set p4a.branch=master when I used buildozer to run the build first time this error popped up. After searching on the internet I found the same problem in #1691. So what I did is reran the buildozer android debug command, obviously, the same error was shown. Now I when inside the .buildozer folder and navigated to python-for-android source downloaded by buildozer and then navigated to _android.pyx file and manually did the patch myself and also I deleted the build folder so that buildozer does a rebuild with the new patched python-for-android and it is now working properly. I didn't get any side effects by applying this patch. |
Thanks @SyncCodes. I tried editing both to apply the patch but when I deployed to my phone I still got the same error. So perhaps it didnt overwrite the old APK on my phone. I will try changing the project name and see if that helps. |
@SyncCodes I am importing The thing is that this patch shouldn't be required as the code is set up right now, so it doesn't make too much sense to just blindly apply it without understanding what is going on. I am still suspecting you guys may have accidentally used an older p4a version without realizing, and we should rule that out (or find out whatever else is going on) before just committing unnecessary conditionals into the code |
Actually @SyncCodes said he/she did put p4a.branch=master into the buildozer.spec file and it still resulted in the same error. Regardless, I created a new app folder named helloTest1 and pasted in two files. These are main.py and buildozer.spec. The contents are listed below. I am compiling now and will let you know how it goes. Note that the spec file now contains p4a.branch=master main.py
buildozer.spec
|
@leematthewshome for what it's worth, if that |
Results unfortunately as before....
|
I assume by "manually wiping" .buildozer you mean deleting the .buildozer directory. That is why i actually started with a completely new folder structure with only main.py and buildozer.spec in the folder. There was no .buildozer as I did not copy the directory from the previous test, only the two files. |
@Jonast I did remove |
oh right, I'm wondering... would |
@Jonast what @leematthewshome did can you do the same and see if you can recreate the error? Can you test this in a fresh vm ? |
Thanks for the update guys. @Jonast I think develop and master are pretty aligned on that one. However something related to cython rings the bell, for instance if it's installed from pip2, maybe? |
OK. As per @SyncCodes I tried with the patch and it worked. Here is what i did:
patch applied:
|
command second command
|
it's using |
"which cython" gives me...
cat $(which cython) gives me....
|
According to buildozer.readthedocs.io/en/latest/installation.html |
Actually I I had trouble with the old Kivy install documentation that was mostly centered around Python2.7 So when I installed Cython I installed using BOTH pip2 and pip3. This was because I had seen some old posts on the net that implied python on android did not support python3, so I installed using both just in case. If Cython was installed into both my Python2.7 and Python3.5 environments (both exist on my PC) and the buildozer spec says to use python3 then I would have thought it would use the Python3 install of Cython. |
Hello, @AndreMiras @Jonast any updates? |
@SyncCodes did you try |
Hello @Jonast the problem is fixed now! I started a fresh VM with the latest ubuntu 18 and now only used the python3, python3-pip and cython under python3 and now it works. Thanks for the support. I would appreciate if you can change the buildozer documents to add support for pip3 installation of cython instead of pip. Because the documentation still uses cython under pip and not pip3. Sorry for the trouble |
Is it possible for the users to get warned by buildozer for the cython version they use? This can be a problem for various users. Like if buildozer is targetting python3 then buildozer will check if cython is from python3 and not python? That warning feature would be greatly appreciated |
Actually, if you put osx.python_version = 3 in the buildozer spec file shouldnt it just use cython from python3? I cant see a scenario where you would want to use python2.7 cython to build a python3 targeted app. For an existing PC where I have cython installed with both pip and pip3, how can I fix my system so it uses the correct version of cython with buildozer? Will just uninstalling with pip result in it falling back to the pip3 installed version? |
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 |
- call Cython via `python -m Cython` to avoid picking one not matching the current python version (which can happen if just calling `Cython`) - make sure Cython is present in Dockerfile.py3 and Dockerfile.py2 - make sure python 2 is available in Dockerfile.py3 - this should fix kivy#1885
Reopening for now since the fix wasn't actually validated. If anyone affected would be interested in retesting, let me know so we can figure out if this actually helped with anything (otherwise I will close this ticket in a week or two) |
I am interested in retesting. Its been a long time since i looked at Kivy as i have been focused on the pure Python devlopment of my project. I just started familiarising myself again. I assume to test i will need to update my buildozer install, is that correct? If so, how should i update it? Do i just run the following... pip install --upgrade buildozer |
(someone of the other devs please correct me if I got this wrong! I don't really use buildozer myself) edit: oh and you need to set p4a to the dev version in your spec file of course, the |
I tested today and deleted all .buildozer files. Ran a build again and watched it download py4a in the comments. The following is what it said: git clone -b master --single-branch https://github.com/kivy/python-for-android.git python-for-android Still got the same error with the resulting apk file when installed on a Samsung phone. The app failed with the "TypeError: must be str not bytes". (Error message detected using adb logcat when open the app). Tried running build with another demo app that I have not created before and got exactly the same result. Still failed with the same error. |
Versions
(seems to be running Python 3.7.1 on Android based on the logs)
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.
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...
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?
The text was updated successfully, but these errors were encountered: