No module named pars when executing python3 script directly
pars
in the django app I have made under INSTALLED_APPS
within settings.py
When i run this python script directly from bash that includes:
from django.db import models
from pars.models import tbl1, tbl2, etc
technologytitle=soup.find("h1").text
try:
technology=CMS(nm=technologytitle)
technology.save()
print("saved techology: {}".format(technologytitle))
except IntegrityError as e:
print("Integrity error occurring with saving: {} {}".format(technologytitle, e))
Im getting an error of:
ModuleNotFoundError: No module named 'pars'
ive done a ton of research, but cant seem to figure out why this is happening.
Thanks
you can not run this script directly without changes.
Read more here: https://docs.djangoproject.com/en/4.1/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage
in your case:
import django
django.setup()
# Now this script or any imported module can use any part of Django it needs.
from pars.models import CMS
# you need import beautifulsoup as soup
technologytitle=soup.find("h1").text
try:
technology=CMS(nm=technologytitle)
technology.save()
print(f'saved techology: {technologytitle}')
except IntegrityError as e:
print(f'Integrity error occurring with saving: {technologytitle} {e}')