Skip to content
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

How to add a hook for textblob in pyinstaller #185

Closed
priyanka22kar opened this issue Dec 28, 2017 · 7 comments
Closed

How to add a hook for textblob in pyinstaller #185

priyanka22kar opened this issue Dec 28, 2017 · 7 comments

Comments

@priyanka22kar
Copy link

priyanka22kar commented Dec 28, 2017

when i 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
your help will be really appreciated .
thank you

@jschnurr
Copy link
Collaborator

Looks very similar to #134.

@jschnurr
Copy link
Collaborator

I suspect pyinstaller is not bundling the required data files. For polarity (sentiment), the code doesn't complain if en-sentiment.xml is missing:

   if not path:
            path = self._path
        if not os.path.exists(path):
            return

I'm not a pyinstaller expert, but looking at the docs it looks like you can specify additional files by modifying myscript.spec.

Here is a list of data files:

./textblob/en/en-entities.txt
./textblob/en/en-spelling.txt
./textblob/en/en-morphology.txt
./textblob/en/en-context.txt
./textblob/en/en-lexicon.txt
./textblob/en/en-sentiment.xml

For your use case, only en-sentiment.xml is required, but it probably makes sense to include them all. In myscript.spec, try this:

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

Can you give that a try? If that's the issue, I'll look at a PR that raises a useful error.

@priyanka22kar
Copy link
Author

@jschnurr thank you i'll try it

@sloria
Copy link
Owner

sloria commented Aug 3, 2018

Hope Jeff's suggestion worked out. Closing this for now.

@sloria sloria closed this as completed Aug 3, 2018
@AshishDhadwal
Copy link

i added the commands in .spec and i get an error
3573 INFO: Appending 'datas' from .spec
Traceback (most recent call last):
File "c:\programdata\anaconda3\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "c:\programdata\anaconda3\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\ProgramData\Anaconda3\Scripts\pyinstaller.exe_main
.py", line 9, in
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller_main
.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller_main_.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
exec(text, spec_namespace)
File "", line 21, in
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 252, in init
for name, pth in format_binaries_and_datas(datas, workingdir=spec_dir):
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\utils.py", line 502, in format_binaries_and_datas
src_root_path_or_glob = os.path.normpath(src_root_path_or_glob)
File "c:\programdata\anaconda3\lib\ntpath.py", line 474, in normpath
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not tuple

@MrScottyTay
Copy link

I have done just this and even checked if the files were copied over into the exe directory and they were. Yet I'm still getting 0s when running the exe.

I'm running python 3.7.3 and had to change the source code for pyinstaller to get the nltk import to work. Do you think the issue may have come from this.

@kpourdeilami
Copy link

I had the same issue and adding those files in the correct path worked for me. Make sure the files get copied to textblob/en path in your final output. These are the arguments with PyInstaller to generate my spec file:

INSTALL_PATH=$(pip3 show textblob | grep Location)
pyinstaller \
    --add-data ${INSTALL_PATH:10}/textblob/en/en-entities.txt:textblob/en \
    --add-data ${INSTALL_PATH:10}/textblob/en/en-morphology.txt:textblob/en \
    --add-data ${INSTALL_PATH:10}/textblob/en/en-spelling.txt:textblob/en \
    --add-data ${INSTALL_PATH:10}/textblob/en/en-context.txt:textblob/en \
    --add-data ${INSTALL_PATH:10}/textblob/en/en-lexicon.txt:textblob/en \
    --add-data ${INSTALL_PATH:10}/textblob/en/en-sentiment.xml:textblob/en \
    <your python file>.py

I Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants