ModuleNotFoundError: 'ms-identity-web' Active Directory Django App

coder1608 0 Reputation points
2023-04-16T17:53:43.5666667+00:00

I successfully installed "ms-identity-web" using a Bash-File with the command: pip install git+https://github.com/azure-samples/ms-identity-python-utilities@main as described in this Tutorial: https://learn.microsoft.com/en-us/training/modules/msid-django-web-app-sign-in/3-exercise-register-django-web-app The Bash-File is executed during building with GitHub-Actions in the workflowfile.yml:

- name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate

 - name: install MSIdentity
        run : |
          chmod +x MSIdent.sh
          ./MSIdent.sh

 - name: Install dependencies
        run: pip install -r requirements.txt

During Building I get the following notifiation:

Collecting git+https://github.com/azure-samples/ms-identity-python-utilities@main
  Cloning https://github.com/azure-samples/ms-identity-python-utilities (to revision main) to /tmp/pip-req-build-6laxvfdk
  Running command git clone --filter=blob:none --quiet https://github.com/azure-samples/ms-identity-python-utilities /tmp/pip-req-build-6laxvfdk
  Resolved https://github.com/azure-samples/ms-identity-python-utilities to commit 9b32cef36c6c0b73c1b3237fdd66128d89f90a62
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: msal<2,>=1.6.0 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from ms-identity-web==0.16.6) (1.21.0)
Requirement already satisfied: cryptography<41,>=0.6 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from msal<2,>=1.6.0->ms-identity-web==0.16.6) (40.0.2)
Requirement already satisfied: requests<3,>=2.0.0 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from msal<2,>=1.6.0->ms-identity-web==0.16.6) (2.28.2)
Requirement already satisfied: PyJWT[crypto]<3,>=1.0.0 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from msal<2,>=1.6.0->ms-identity-web==0.16.6) (2.6.0)
Requirement already satisfied: cffi>=1.12 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from cryptography<41,>=0.6->msal<2,>=1.6.0->ms-identity-web==0.16.6) (1.15.1)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from requests<3,>=2.0.0->msal<2,>=1.6.0->ms-identity-web==0.16.6) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from requests<3,>=2.0.0->msal<2,>=1.6.0->ms-identity-web==0.16.6) (3.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from requests<3,>=2.0.0->msal<2,>=1.6.0->ms-identity-web==0.16.6) (1.26.15)
Requirement already satisfied: certifi>=2017.4.17 in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from requests<3,>=2.0.0->msal<2,>=1.6.0->ms-identity-web==0.16.6) (2022.12.7)
Requirement already satisfied: pycparser in /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages (from cffi>=1.12->cryptography<41,>=0.6->msal<2,>=1.6.0->ms-identity-web==0.16.6) (2.21)
Building wheels for collected packages: ms-identity-web
  Building wheel for ms-identity-web (setup.py): started
  Building wheel for ms-identity-web (setup.py): finished with status 'done'
  Created wheel for ms-identity-web: filename=ms_identity_web-0.16.6-py3-none-any.whl size=17513 sha256=8607bf7ce4f27cadc820997675df99c245606f77024bbdc7e00a5adfea7d10e4
  Stored in directory: /tmp/pip-ephem-wheel-cache-4sot6plb/wheels/c8/41/b0/70a104f90dd032433652eabd8cfacc2c0e4b025db91a03b83c
Successfully built ms-identity-web
Installing collected packages: ms-identity-web
Successfully installed ms-identity-web-0.16.6
Notice:  A new release of pip is available: 23.0.1 -> 23.1
Notice:  To update, run: pip install --upgrade pip

But when I start running the Django App via Azure I get the following error message:

2023-04-16T10:55:23.072620824Z     mod = importlib.import_module(self.SETTINGS_MODULE)
2023-04-16T10:55:23.072625224Z   File "/opt/python/3.9.16/lib/python3.9/importlib/__init__.py", line 127, in import_module
2023-04-16T10:55:23.072629724Z     return _bootstrap._gcd_import(name[level:], package, level)
2023-04-16T10:55:23.072634124Z   File "
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,809 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Shweta Mathur 28,106 Reputation points Microsoft Employee
    2023-04-19T07:44:58.0466667+00:00

    Hi @coder1608 ,

    Thanks for reaching out.

    I understand you are trying to execute Django application but getting module not found error.

    I reproduced the scenario in my lab based on tutorial link you shared and got the same error 'ModuleNotFoundError: No module named 'ms_identity_web'

    It is because the module 'ms__identity__web' is not installed where the application resides and installing the modules in the temporary location.

    To resolve the issue:

    Navigate to the project folder to install the project dependencies(requirement.txt)

    (djangoenv) PS C:\Shweta\Azure Samples\ms-identity-python-django-tutorial\1-Authentication\sign-in> pip install -r requirements.txt

    djangoenv is my virtual environment to run Django application and it will install all the dependencies at above mentioned path where application is running.

    enter image description here

    Reference Sample : https://github.com/Azure-Samples/ms-identity-python-django-tutorial/tree/main/1-Authentication/sign-in Hope this will help.

    Thanks,

    Shweta

    0 comments No comments

  2. Rorisang Sitoboli 0 Reputation points
    2023-05-09T04:48:24.4233333+00:00

    Please run the following command in the shell/anaconda prompt

    pip install git+https://github.com/azure-samples/ms-identity-python-utilities@main

    Ref: https://learn.microsoft.com/en-us/training/modules/msid-django-web-app-sign-in/3-exercise-register-django-web-app

    See the section: Configure Django web app to use app registration details

    0 comments No comments