问题
I'm using Linux App Service. I'm trying to deploy python 3.6 flask application through the Azure DevOps pipeline. It worked fine for a basic app but when I add an additional code (spacy module), it started to throw
2019-12-24T18:07:33.079953940Z __import__(module)
2019-12-24T18:07:33.079961840Z File "/home/site/wwwroot/application.py", line 3, in <module>
2019-12-24T18:07:33.079970340Z from Data_Cleanup_utility.clear_content_utility import ClearContent
2019-12-24T18:07:33.079978440Z File "/home/site/wwwroot/Data_Cleanup_utility/clear_content_utility.py", line 12, in <module>
2019-12-24T18:07:33.079986741Z import spacy
2019-12-24T18:07:33.079994741Z **ModuleNotFoundError: No module named 'spacy'**
2019-12-24T18:07:33.084726683Z [2019-12-24 18:07:33 +0000] [51] [INFO] Worker exiting (pid: 51)
2019-12-24T18:07:33.170423056Z [2019-12-24 18:07:33 +0000] [48] [INFO] Shutting down: Master
2019-12-24T18:07:33.172257711Z [2019-12-24 18:07:33 +0000] [48] [INFO] Reason: Worker failed to boot.
I have added the dependency modules in the requirement.txt
Flask==1.0.2
Flask-Cors==3.0.8
Flask-RESTful==0.3.7
fastai==1.0.59
numpy==1.17.4
pandas==0.25.3
requests==2.22.0
spacy==2.2.3
spacy-langdetect==0.1.2
and azurepipeline.yml
- script: |
python -m venv antenv
source antenv/bin/activate
python -m pip install --upgrade pip
pip install setup
pip install -r requirements.txt
python -m spacy download es
workingDirectory: $(projectRoot)
displayName: "Install requirements"
and my code clear_content_utility.py
import spacy
from spacy_langdetect import LanguageDetector
nlp = spacy.load('es')
nlp.add_pipe(LanguageDetector(), name='language_detector', last=True)
did anyone face the above issue? appreciate your help.
回答1:
Here is something you should do:
- Please ensure to activate the virtual environment before executing any code, also make sure to check if your installed package is actually in there in your VENV.
I would suggest you to create new VENV and try activating it.
Secondly , you can language data has been moved to a submodule
**spacy.lang**
to keep thing cleaner and better organised.E.g. instead of using
spacy.en
, you now import fromspacy.lang.en
python -m spacy download en_core_web_sm
import spacy
nlp = spacy.load("en_core_web_sm")
Additional reference:
https://www.pythonanywhere.com/forums/topic/13328/
ImportError: No module named 'spacy.en'
Hope it helps.
来源:https://stackoverflow.com/questions/59472245/azure-python-deployment-spacy-nomodule-found-exception