Closed ghost closed 8 months ago
I have the same problem with you, where can we save the 'nltk_data' folder when building into apk? have you found a solution?
Do we have any solutions so far?
Hello, what happens is that if you leave the NLTK data file in the app's folder, the user does not have permission to access it. So the alternative I found was to compress the "nltk_data" and when the user opens the app for the first time it will extract it to the "Android" folder where the user has access. Then I add this folder to be one of the paths to the "nltk_data".
follow the way it worked for me.
put this code in your main.py.
from kivy.utils import platform
import nltk
if __name__ == "__main__":
if platform == 'android':
localNLTK = "/storage/emulated/0/Android/nltk_data"
if os.path.isdir('/storage/emulated/0/Android/nltk_data'):
if localNLTK not in nltk.data.path:
nltk.data.path.append(localNLTK)
else:
from zipfile import ZipFile
with ZipFile('nltk_data.zip', 'r') as zipObj:
zipObj.extractall(localNLTK)
if localNLTK not in nltk.data.path:
nltk.data.path.append(localNLTK)
Put this file in the same directory as main.py
sorry for my english, hope this helps.
Hi, I'm facing the same issue, but since I'm using Colab to build my app. Can someone please tell me how to go about including nltk in my Android app? Right now I'm getting this error: LookupError: 11-15 18:17:38.562 24746 24893 I python : LookupError: 11-15 18:17:38.562 24746 24893 I python : **** 11-15 18:17:38.562 24746 24893 I python : Resource stopwords not found. 11-15 18:17:38.562 24746 24893 I python : Please use the NLTK Downloader to obtain the resource: 11-15 18:17:38.562 24746 24893 I python : 11-15 18:17:38.562 24746 24893 I python : >>> import nltk 11-15 18:17:38.562 24746 24893 I python : >>> nltk.download('stopwords') 11-15 18:17:38.562 24746 24893 I python : 11-15 18:17:38.562 24746 24893 I python : For more information see: https://www.nltk.org/data.html 11-15 18:17:38.562 24746 24893 I python : 11-15 18:17:38.562 24746 24893 I python : Attempted to load corpora/stopwords.zip/stopwords/ 11-15 18:17:38.562 24746 24893 I python : 11-15 18:17:38.562 24746 24893 I python : Searched in: 11-15 18:17:38.563 24746 24893 I python : - '/data/nltk_data' 11-15 18:17:38.563 24746 24893 I python : - 'nltk_data' 11-15 18:17:38.563 24746 24893 I python : - 'share/nltk_data' 11-15 18:17:38.563 24746 24893 I python : - 'lib/nltk_data' 11-15 18:17:38.563 24746 24893 I python : - '/usr/share/nltk_data' 11-15 18:17:38.563 24746 24893 I python : - '/usr/local/share/nltk_data' 11-15 18:17:38.563 24746 24893 I python : - '/usr/lib/nltk_data' 11-15 18:17:38.563 24746 24893 I python : - '/usr/local/lib/nltk_data' 11-15 18:17:38.563 24746 24893 I python : ****
Hello, what happens is that if you leave the NLTK data file in the app's folder, the user does not have permission to access it. So the alternative I found was to compress the "nltk_data" and when the user opens the app for the first time it will extract it to the "Android" folder where the user has access. Then I add this folder to be one of the paths to the "nltk_data".
follow the way it worked for me.
put this code in your main.py.
from kivy.utils import platform import nltk if __name__ == "__main__": if platform == 'android': localNLTK = "/storage/emulated/0/Android/nltk_data" if os.path.isdir('/storage/emulated/0/Android/nltk_data'): if localNLTK not in nltk.data.path: nltk.data.path.append(localNLTK) else: from zipfile import ZipFile with ZipFile('nltk_data.zip', 'r') as zipObj: zipObj.extractall(localNLTK) if localNLTK not in nltk.data.path: nltk.data.path.append(localNLTK)
Put this file in the same directory as main.py
sorry for my english, hope this helps.
@mr-lops I tried your code but during running the app crashes with the logcat saying "FileNotFoundError: [Errno 2] No such file or directory: 'nltk_data.zip'". I'd kept the zip file in the main folder among other program files. Also, I'm using Google Colab to build my apk using bulldozer. Let me know if I need to make any changes.
👋 @ghost, we use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project. Let us know if this comment was made in error, and we'll be happy to reopen the issue.
Versions
Description
Hello, I am using NLTK with kivy. The app works perfectly running with python main.py, but when debugging on the phone it gives an error. The logcat message says that it could not find the "punkt resource", but it exists in the directory in which it was searched.
I've already tried to move directories and use the suggested command (nltk.download ('punkt')), but nothing worked.
Any solution?
Thanks!
buildozer.spec
Command:
Spec file:
--------- beginning of system --------- beginning of main 06-10 18:05:10.765 22521 22556 I python : [INFO ] [Clipboard ] Provider: android 06-10 18:05:18.275 22521 22556 I python : [INFO ] [Base ] Leaving application in progress... 06-10 18:05:18.275 22521 22556 I python : Traceback (most recent call last): 06-10 18:05:18.275 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/app/main.py", line 26, in
06-10 18:05:18.275 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/app.py", line 950, in run
06-10 18:05:18.275 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 561, in runTouchApp
06-10 18:05:18.275 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 335, in mainloop
06-10 18:05:18.275 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 379, in idle
06-10 18:05:18.275 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 330, in dispatch_input
06-10 18:05:18.285 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/base.py", line 296, in post_dispatch_input
06-10 18:05:18.285 22521 22556 I python : File "kivy/_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
06-10 18:05:18.285 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivymd/uix/behaviors/ripplebehavior.py", line 245, in on_touch_up
06-10 18:05:18.285 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivymd/uix/button.py", line 969, in on_touch_up
06-10 18:05:18.285 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/uix/behaviors/button.py", line 179, in on_touch_up
06-10 18:05:18.285 22521 22556 I python : File "kivy/_event.pyx", line 705, in kivy._event.EventDispatcher.dispatch
06-10 18:05:18.285 22521 22556 I python : File "kivy/_event.pyx", line 1248, in kivy._event.EventObservers.dispatch
06-10 18:05:18.285 22521 22556 I python : File "kivy/_event.pyx", line 1132, in kivy._event.EventObservers._dispatch
06-10 18:05:18.285 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/kivy/lang/builder.py", line 57, in custom_callback
06-10 18:05:18.285 22521 22556 I python : File "/data/data/org.test.myapp/files/app/textointegra.kv", line 27, in
06-10 18:05:18.285 22521 22556 I python : on_release: app.sumarizar(txtEntrada.text)
06-10 18:05:18.285 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/app/main.py", line 22, in sumarizar
06-10 18:05:18.285 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/app/resumo.py", line 38, in summarize
06-10 18:05:18.285 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/app/resumo.py", line 21, in split_sentences
06-10 18:05:18.295 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/nltk/tokenize/init.py", line 106, in sent_tokenize
06-10 18:05:18.295 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/nltk/data.py", line 752, in load
06-10 18:05:18.295 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/nltk/data.py", line 877, in _open
06-10 18:05:18.295 22521 22556 I python : File "/home/alexandre/Documents/ProjetosComerciais/PlayStore/Andamento/Summarizer/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/myapp/nltk/data.py", line 585, in find
06-10 18:05:18.295 22521 22556 I python : LookupError:
06-10 18:05:18.295 22521 22556 I python : **
06-10 18:05:18.295 22521 22556 I python : Resource punkt not found.
06-10 18:05:18.295 22521 22556 I python : Please use the NLTK Downloader to obtain the resource:
06-10 18:05:18.295 22521 22556 I python :
06-10 18:05:18.295 22521 22556 I python : >>> import nltk 06-10 18:05:18.295 22521 22556 I python : >>> nltk.download('punkt') 06-10 18:05:18.295 22521 22556 I python :
06-10 18:05:18.295 22521 22556 I python : For more information see: https://www.nltk.org/data.html 06-10 18:05:18.295 22521 22556 I python :
06-10 18:05:18.295 22521 22556 I python : Attempted to load tokenizers/punkt/PY3/english.pickle 06-10 18:05:18.295 22521 22556 I python :
06-10 18:05:18.295 22521 22556 I python : Searched in: 06-10 18:05:18.295 22521 22556 I python : - '/data/nltk_data' 06-10 18:05:18.295 22521 22556 I python : - 'nltk_data' 06-10 18:05:18.295 22521 22556 I python : - 'share/nltk_data' 06-10 18:05:18.295 22521 22556 I python : - 'lib/nltk_data' 06-10 18:05:18.295 22521 22556 I python : - '/usr/share/nltk_data' 06-10 18:05:18.295 22521 22556 I python : - '/usr/local/share/nltk_data' 06-10 18:05:18.295 22521 22556 I python : - '/usr/lib/nltk_data' 06-10 18:05:18.295 22521 22556 I python : - '/usr/local/lib/nltk_data' 06-10 18:05:18.295 22521 22556 I python : - '' 06-10 18:05:18.305 22521 22556 I python : ** 06-10 18:05:18.305 22521 22556 I python :
06-10 18:05:18.305 22521 22556 I python : Python for android ended.