Closed lemoncalamitous closed 6 years ago
I verified on this issue I am facing, this is an issue of PyInstaller. You must use PyInstaller's dev branch to compile your application.
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Also, in compiling your application with spacy using PyInstaller, ypu must use hidden imports such as:
--hidden-import cymem.cymem --hidden-import thinc.linalg --hidden-import murmurhash.mrmr --hidden-import cytoolz.utils --hidden-import cytoolz._signatures --hidden-import spacy.strings --hidden-import spacy.morphology --hidden-import spacy.lexeme --hidden-import spacy.tokens --hidden-import spacy.gold --hidden-import spacy.tokens.underscore --hidden-import spacy.parts_of_speech --hidden-import dill --hidden-import spacy.tokens.printers --hidden-import spacy.tokens._retokenize --hidden-import spacy.syntax --hidden-import spacy.syntax.stateclass --hidden-import spacy.syntax.transition_system --hidden-import spacy.syntax.nonproj --hidden-import spacy.syntax.nn_parser --hidden-import spacy.syntax.arc_eager --hidden-import thinc.extra.search --hidden-import spacy.syntax._beam_utils --hidden-import spacy.syntax.ner --hidden-import thinc.neural._classes.difference
Compiling python script with spaCy to an executable became successful on my end. But, upon using spaCy, It cannot find the spaCy data directory.
[E049] Can't find spaCy data directory: 'None'. Check your installation and permissions, or use spacy.util.set_data_path to customise the location if necessary.
I use spacy.load('path to my pretrained model from a config file')
. It's running on plain python, but not on the executable. Any thoughts on this?
It's possible that this is a permissions / environment thing, or maybe it's because the default data directory in spacy/data
wasn't included in your executable? In any case, you can always set the path manually via the set_data_path
helper:
from spacy.util import set_data_path
set_data_path('/path/to/spacy/data')
Thanks @ines for the recommendation! It looks like setting the data path from the config file to set_data_path
function worked.
But upon continuing packaging my software, another error occured:
[E048] Can't import language en from spacy.lang.
My current model has a meta.json file that has the following values:
{ "lang":"en", "name":"model", "version":"0.0.0", "spacy_version":">=2.0.11", "description":"", "author":"", "email":"", "url":"", "license":"", "vectors":{ "width":300, "vectors":1250792, "keys":999994, "name":null }, "pipeline":[
] }
Any thoughts on this?
That's very strange ā the meta is correct. The error seems to occur here in get_lang_class
when spaCy is trying to import spacy.lang.en
dynamically.
Maybe some of the modules weren't packaged correctly? If you run the following code manually, does it produce the same error?
import spacy.lang.en # import module
from spacy.lang.en import English # import something from module
# use the get_lang_class helper
from spacy.util import get_lang_class
cls = get_lang_class('en')
You could also check that all files are where they should be ā for example spacy/lang/en
should exist and have an __init__.py
, etc.
Hi @ines . I tried the code you recommend and this works.
import spacy.lang.en from spacy.lang.en import English from spacy.util import get_lang_class cls = get_lang_class('en') cls <class 'spacy.lang.en.English'>
Based on my observation, it seems that (again) it's PyInstaller's fault. I use 4 fastText models that all have English meta, so I tried adding hidden import again.
--hidden-import spacy.lang.en
Upon packaging my application along with so many hidden imports, it worked, finally! If I am going to use other languages, creating hook-spacy.lang.py then importing all languages will work better. Just place this hook Python file inside your Python environment's PyInstaller hooks folder.
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('spacy.lang')
Hope that this will also help other guys who use spaCy on their packaged application. Thanks for the support!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
How to reproduce the problem
I am currently using conda. I've created a clean environment with the following yml file:
And then tried installing spaCy 2.0.11 on that environment using pip and conda.
In PyInstaller, I added the following --hidden-import since they cannot be imported from compiled application:
Here's the error message that I cannot resolve:
I am not sure if the issue is on PyInstaller or spaCy. Any help is appreciated. Thanks!
My Environment