我正在使用Linux App Service。我正在尝试通过Azure DevOps管道部署python 3.6 flask应用程序。对于基本应用程序来说,它工作正常,但是当我添加其他代码(spacy模块)时,它开始抛出
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.
我已在 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
和 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"
和我的代码 clear_content_utility.py
import spacy
from spacy_langdetect import LanguageDetector
nlp = spacy.load('es')
nlp.add_pipe(LanguageDetector(), name='language_detector', last=True)
有人遇到上述问题吗?感谢您的帮助。
答案 0 :(得分:0)
这是您应该做的事情:
我建议您创建新的VENV并尝试将其激活。
第二,您可以将语言数据移至子模块**spacy.lang**
中,以保持内容整洁和井井有条。
例如。您现在可以从 spacy.en
spacy.lang.en
python -m spacy download en_core_web_sm
import spacy
nlp = spacy.load("en_core_web_sm")
其他参考:
https://www.pythonanywhere.com/forums/topic/13328/
ImportError: No module named 'spacy.en'
希望有帮助。