0

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.

mbb5079
  • 646
  • 1
  • 5
  • 10

1 Answers1

0

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 from spacy.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.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
  • Thanks for your response. I'm trying to activate the new virtual environment but still, it's only taking base python. – Shiva Perumalsamy Dec 27 '19 at 01:23
  • try Creating a new venv by virtualenv with option "--no-site-packages" virtualenv --no-site-packages --python=/xx/xx/bin/python my_env_nmae – Mohit Verma Dec 27 '19 at 03:33
  • There are multiple issues with deployment. Azure Pipeline had a problem. I have resolved it using Viscose. Thanks for your help – Shiva Perumalsamy Dec 28 '19 at 04:06
  • Hi, @Siva I am facing the same issue. Could you please detail what you did to fix it? – Royston46 Apr 26 '20 at 16:34
  • @Royston46 you need to add the following configuration in Azure Web App to activate/use the virtualenv which you created and installed all the dependency. *WEBSITE_RUN_FROM_PACKAGE = 1* if you're not adding this configuration, the web app still use the base python. – Shiva Perumalsamy May 03 '20 at 01:17