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

Unable load spacy with pyintsaller on other system #3592

Closed
AshishDhadwal opened this issue Apr 16, 2019 · 6 comments
Closed

Unable load spacy with pyintsaller on other system #3592

AshishDhadwal opened this issue Apr 16, 2019 · 6 comments
Labels
install Installation issues

Comments

@AshishDhadwal
Copy link

I had created an exe file which works fine on my system but when i try to run on other system i was unable to load the model.

Your Environment

  • Operating System:Windows 10
  • Python Version Used:3.6
  • spaCy Version Used:2.0.18
  • Environment Information:64 bit

When i run exe in other system in which python is not installed its throws me below error

File "spacy\util.py", line 109, in load_model
OSError: [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 had set spacy.util.set_data_path to to data location
In my .spec file i had included below imports:

datas=[("D:/anaconda3/Lib/site-packages/ftfy/char_classes.dat", "ftfy"),('model1.json', '.' ),('model1.h5', '.' ),('wordcloud\*.py','wordcloud'),('wordcloud\*.pyd','wordcloud'),('wordcloud\__pycache__\*.pyc','wordcloud'),('wordcloud\stopwords','wordcloud'),('wordcloud\DroidSansMono.ttf','wordcloud'),('D:/anaconda3/Lib/site-packages/spacy/data','spacy'),('D:/anaconda3/Lib/site-packages/spacy/data/*.py','spacy'),('D:/anaconda3/Lib/site-packages/spacy/data/en_core_web_sm/*.py','spacy'),('D:/anaconda3/Lib/site-packages/spacy/data/en_core_web_sm/*.json','spacy'),('D:/anaconda3/Lib/site-packages/spacy/data/en_core_web_sm/*.py','spacy'),('D:/anaconda3/Lib/site-packages/spacy/data/en_core_web_sm/__pycache__/*.pyc','spacy'),('D:/anaconda3/Lib/site-packages/spacy/data/en_core_web_sm/en_core_web_sm-2.0.0/*.json','spacy'),('D:/anaconda3/Lib/site-packages/spacy/data/en_core_web_sm/en_core_web_sm-2.0.0','spacy')],
             hiddenimports=['cython','sklearn.pipeline' ,'sklearn', 'sklearn.ensemble', 'sklearn.neighbors.typedefs', 'sklearn.neighbors.quad_tree', 'sklearn.tree._utils','h5py.defs', 'h5py.utils', 'h5py.h5ac', 'h5py._proxy','PIL','cymem.cymem', 'thinc.linalg', 'murmurhash.mrmr', 'cytoolz.utils', 'cytoolz._signatures', 'spacy.strings', 'spacy.morphology', 'spacy.lexeme', 'spacy.tokens', 'spacy.gold', 'spacy.tokens.underscore', 'spacy.parts_of_speech', 'dill', 'spacy.tokens.printers', 'spacy.tokens._retokenize', 'spacy.syntax', 'spacy.syntax.stateclass', 'spacy.syntax.transition_system', 'spacy.syntax.nonproj', 'spacy.syntax.nn_parser', 'spacy.syntax.arc_eager', 'thinc.extra.search', 'spacy.syntax._beam_utils', 'spacy.syntax.ner', 'thinc.neural._classes.difference', 'spacy.vocab', 'spacy.lemmatizer', 'spacy._ml', 'ftfy', 'spacy.lang', 'spacy.lang.en','spacy.util','pylab'],

Any help would be highly appreciated ?

@ines ines added the install Installation issues label Apr 16, 2019
@ines
Copy link
Member

ines commented Apr 16, 2019

Where are you calling set_data_path?

And does importing the model as a module work? If it's installed correctly, you should also be able to do the following:

import en_core_web_sm

nlp = en_core_web_sm.load()

@ines ines added the more-info-needed This issue needs more information label Apr 16, 2019
@AshishDhadwal
Copy link
Author

i set data path below:
spacy.util.set_data_path('D:/anaconda3/Lib/site-packages/spacy/data/en_core_web_sm')

&
import en_core_web_sm

nlp = en_core_web_sm.load()

i am able load model with these two commands.

Spacy is not able to work in exe mode on other system.

@no-response no-response bot removed the more-info-needed This issue needs more information label Apr 16, 2019
@ines
Copy link
Member

ines commented Apr 17, 2019

I think the path is the problem here: The data path should be the path to the data directory, not the model itself:

spacy.util.set_data_path('D:/anaconda3/Lib/site-packages/spacy/data')

Also, you might want to check out #2536 for more details on spaCy + PyInstaller.

@ines ines added the more-info-needed This issue needs more information label Apr 17, 2019
@no-response
Copy link

no-response bot commented May 1, 2019

This issue has been automatically closed because there has been no response to a request for more information from the original author. With only the information that is currently in the issue, there's not enough information to take action. If you're the original author, feel free to reopen the issue if you have or find the answers needed to investigate further.

@no-response no-response bot closed this as completed May 1, 2019
@AshishDhadwal
Copy link
Author

Please include this in your py script after sleepless nights i was able to load exe

def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath("__file__")))
    return os.path.join(base_path, relative_path)

spacy.util.set_data_path= resource_path('D:/anaconda3/Lib/site-packages/spacy/data')



nlp = spacy.load('en_core_web_sm')

and in .spec file

datas =[('D:\anaconda3\Lib\site-packages\spacy\data','.'),('D:\anaconda3\Lib\site-packages\spacy\data\en_core_web_sm','spacy\data\en_core_web_sm'),('D:\anaconda3\Lib\site-packages\en_core_web_sm','en_core_web_sm'),('D:\anaconda3\Lib\site-packages\spacy\data\en_core_web_sm\en_core_web_sm-2.0.0','spacy\data\en_core_web_sm\en_core_web_sm-2.0.0')]

@no-response no-response bot removed the more-info-needed This issue needs more information label May 3, 2019
@no-response no-response bot reopened this May 3, 2019
@lock
Copy link

lock bot commented Jun 2, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
install Installation issues
Projects
None yet
Development

No branches or pull requests

2 participants