I am trying to run a standalone script in django 4.1. I have the setup as suggested in this post at the top of my file:
JavaScript
x
5
1
import os
2
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "path_to_settings.settings")
3
import django
4
django.setup()
5
However, on the 4th line, I get the following error:
ModuleNotFoundError: No module named 'sport_api'
This is my INSTALLED_APPS
in settings.py
JavaScript
1
17
17
1
INSTALLED_APPS = [
2
'django.contrib.admin',
3
'django.contrib.auth',
4
'django.contrib.contenttypes',
5
'django.contrib.sessions',
6
'django.contrib.messages',
7
'django.contrib.staticfiles',
8
9
# applications
10
'sport_api',
11
'sport_bet',
12
13
# library
14
'rest_framework',
15
'corsheaders',
16
]
17
How do I get around this error?
Update:
Advertisement
Answer
You have to move the script to the manage.py
layer. That’s the only thing that got this to work for me.