Newbie here . Please have mercy (and patience)!
[EDIT: solved, see my comment]
I created a small script that reads a CSV (a list of filenames) and creates objects accordingly:
import os os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') import django django.setup() import csv import sys from myapp.models import Campaign, Annotation campaign_name = "a_great_name" path_to_csv = "filenames.csv" with open(path_to_csv) as f: reader = csv.reader(f) filenames = [i for i in reader] new_campaign = Campaign.objects.create(name=campaign_name) for i in filenames: new_annotation = Annotation( campaign=new_campaign, asset_loc = i) new_annotation.save()
I saved this script at the root of my project:
and it worked fine.
… until I decided to move it into a subfolder of my project (it’s a bit like an admin tool that should rarely be used):
Now, when I try to run it, I get this error:
ModuleNotFoundError: No module named 'myproject'
I’m having a hard time understanding why this happens exactly and as a consequence, how to fix it. The various StackOverflow threads I’ve read were not easy enough for my rookie brain.
Thank you in advance for your help!