[Django]-Django-extension runscript No (valid) module for script

1👍

Apart from adding init.py you are not supposed to pass any parameters in the run method.

def run():
     <your code goes here>

2👍

Try adding empty file __init__.py (double underscore) into your /scipts folder and run with:

python manage.py runscript scipts.familiespopulate
👤Fine

0👍

Thanks for the useful comments.
I modified my code in this way:

import csv
from browse.models import families


def run():
   file_path =   "/Users/work/Desktop/StructuRNA/website/scripts/RFAMfamily12.1.txt"
   listoflists = list(csv.reader(open(file_path, 'r'),delimiter='\t'))
print(listoflists)
for row in listoflists:
    families.objects.create(
                rfam_acc=row[0],
                rfam_id=row[1],
                description=row[3],
                author=row[4],
                comment=row[9],
    )

This is all. Now it worked smoothly.
I want to confirm to everyone that my file: familiespopulate.py was in the folder script with the file init.py

The problem seemed to be resolved when I put

file_path = "/Users/work/Desktop/StructuRNA/website/scripts/RFAMfamily12.1.txt"

Inside the run function, removing the parameter file_path from run(file_path).

Another modify to my code was the argument r inside open(file_path, ‘r’), before it was open(file_path, ‘rb’) that should corrispond to read binary.

👤Peter

0👍

I was also getting exactly the same error, I tried all of the solution above but unfortunately did not worked for me. Then I realized my mistake, and I found it.

Inside the script file (which is inside the script/ folder) I used different name for the function, which should be named as ‘run’. So, make sure you checked it as well, if you get this error.

Here you can read more about "runscript"

Leave a comment