0

I am trying to create a .exe file using pyinstaller and execute it it is not fetching any result from b = TextBlob(ar) score = b.sentiment.polarity

it returns proper value when executed on console but return 0 when executed with .exe

def start_dmo():
 print ("Importing all the required packages...")
 from textblob import TextBlob
 input ("press enter to continue")
 print("All Necessary Packages imported")
 input("press enter to continue")
 ar="I cant be more happy with this"
 print(ar)
 b = TextBlob (ar)
 score = b.sentiment.polarity
 print (b.sentiment.polarity)
 input("press enter to continue")
 score = round (score, 2)
 if score > 0.0:
    senti = "Positive"
elif score < 0.0:
    senti = "Negative"
else:
    senti = "Neutral"
 print("Score"+str(score)+"sentiment"+senti)
 input("press enter to continue")

start_dmo()

this is the output when the above code is executed on console

this is the output when the above code is executed on .exe of the same code which is created using pyinstaller

4 Answers4

1

Pyinstaller is not including en-sentiment.xml in the package, so the sentiment analyzer is missing a dependency and returns 0. Textblob doesn't produce an error in this case.

pyinstaller requires that you specify any data files in myscript.spec manually. However, as you've discovered, it appears that cx_Freeze honors the setup.py configuration, which specifies the data files to be included already:

package_data={
  "textblob.en": ["*.txt", "*.xml"]
}

To resolve, modify the pyinstaller myscript.spec file to copy textblob/en/en-sentiment.xml, or switch to cx_Freeze as discussed.

See my post on Github as well.

jschnurr
  • 1,181
  • 6
  • 8
  • This resolved it for me. In my case the issue was intermittent, some texts would return scores, others wouldn't. After explicitly including the files it now works, not sure why some worked before including them however. – Meshi Sep 27 '21 at 08:50
0

Try importing textblob before of your start_dmo function so that pyinstaller is aware of it as a dependency.

from textblob import TextBlob

start_dmo():
    ....
user772401
  • 2,754
  • 3
  • 31
  • 50
0

Issue Solved! Simple Solution Changed pyinstaller to cx_Freeze FYI cx_Freeze works perfectly fine with python 3.6 to know how to create .exe using cx_freeze follow the below link: https://pythonprogramming.net/converting-python-scripts-exe-executables/

if u use numpy or pandas u might need to add option cz it might not import numpy to form ur exe so solve that issue follow below link: Creating cx_Freeze exe with Numpy for Python

Good luck!

0

hey copy textblob from site packages to your working directory and run below in .spec

  a = Analysis(.....
         datas=[( 'textblob/en/*.txt', 'textblob/en' ),
     ( 'textblob/en/*.xml', 'textblob/en' )],
     ....)

it will work

ashu
  • 167
  • 2
  • 12