3

I have an application that analyses text looking for keywords using natural language processing.
I created an executable and it works fine on my computer.
I've sent it to a friend but in his computer he gets an error:

Traceback (most recent call last):
  File "Main.py", line 15, in <module>
  File "Menu.py", line 349, in main_menu
  File "Menu.py", line 262, in analyse_text_menu
  File "Menu.py", line 178, in analyse_text_function
  File "AnalyseText\ProcessText.py", line 232, in process_text
  File "AnalyseText\ProcessText.py", line 166, in generate_keyword_complete_list
  File "AnalyseText\ProcessText.py", line 135, in lemmatize_text
  File "stanza\pipeline\core.py", line 88, in _init_
stanza.pipeline.core.ResourcesFileNotFoundError: Resources file not found at: C:\Users\jpovoas\stanza_resources\resources.json  Try to download the model again.
[26408] Failed to execute script 'Main' due to unhandled exception!

It's looking for resources.json inside a folder in his computer. Even though I've added stanza as a hidden import with pyinstaller.

I'm using a model in another language, as opposed to the default one in english. The model is located in a folder inside the User folder.

The thing is, I don't want the end user to have to download the model separatedly.

I've managed to include the model folder with --add-data C:\Users\Laila\stanza_resources\pt;Stanza" when creating the executable.

It still looks for the model's json file inside the stanza_resources folder that's should be inside the User folder of whoever is using the program.

How do I tell stanza to look for the model inside the executable folder generated instead?

Can I just add stanza.download("language") in my script? If so how do I change stanza's model download folder? I want it to be downloaded into a folder inside the same directory as the executable. How do I do that?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Laila Campos
  • 801
  • 1
  • 8
  • 21

2 Answers2

2

Edit: It would be possible to change the location of the model download by doing the following:

stanza.download("pt", model_dir=...)

It wouldn't be the ideal solution for me though, because I'd like to avoid having to download the model again.

I solved it by passing a value to the model_dir argument when making a pipeline:

npl = stanza.Pipeline(lang='Pt', model_dir='.\\Stanza')

Inside the folder called Stanza I've placed both the model folder (in this case "pt") and the resources.json file.

Laila Campos
  • 801
  • 1
  • 8
  • 21
1

You can try downloading that JSON file.
Here is an snippet for the same.

import urllib.request

json_url = "http://LINK_TO_YOUR_JSON/resources.json"

urllib.request.urlretrieve(json_url, "./resources.json")
Deep
  • 306
  • 1
  • 3
  • 11