"ModuleNotFoundError: No module named 'auth0.v3'" Error when Running Python Script

Last Updated: Sep 16, 2024

Overview

The following error is being returned when attempting to run a Python script, which leverages the auth0-python library, to export users:

>> python3 export.py
Traceback (most recent call last):
File "/export.py", line 7, in <module>
from tools import Config, get_auth0
File "tools.py", line 4, in <module>
from auth0.v3 import Auth0Error
ModuleNotFoundError: No module named 'auth0.v3'

Applies To

  • Python 3
  • Auth0-python library

Cause

The issue is with the 4.0 version of the auth0-python library. The script provided was written prior to that version’s release, so any machines running the newest version of that library will experience that issue for that particular script.

The following is a snippet of the script to show the setup and imports being used:

export.py

import datetime
import os
import subprocess
import time
import wget

from tools import Config, get_auth0

# Export all users from all connections
# Retrieve the gzipped file
# Decompress it


config = Config()
domain = config.import_domain
non_interactive_client_id = config.import_client_id
non_interactive_client_secret = config.import_client_secret

auth0 = get_auth0(non_interactive_client_id, non_interactive_client_secret, domain)
.........


tools.py

import datetime
import os

from auth0.v3 import Auth0Error
from auth0.v3.authentication import GetToken
from auth0.v3.management import Auth0
from dotenv import load_dotenv

# Tools used by the migration process


# Config
# Reads the .env file and loads the values
# Store the start time
# Get elapsed time
class Config:
time_format = "%Y-%m-%dT%H:%M:%S.%fZ"
def __init__(self):
load_dotenv()
............

Solution

If leveraging a Python script that is incompatible with the newest auth0-python version, explicitly setting the version to a previous release (as shown below) should resolve the issue.

pip install auth0-python==3.24.1

Related References