3

I am getting problems running a script that is inside a folder inside of scripts folder using runscript command included in django-extensions.

The folder structure in my project is like:

-apps
-scripts
    -syllabus
        -first.py
    -second.py

The files first.py and second.py are identical.

It has a run function as required by the django-extension runscript command.

def run(*args):
    # my function call for the script.

I have well placed init.py and I can run second.py from the command:

./manage.py runscript second --script-args=excel.xlsx

But somehow I cannot run the first.py file from the runscript command. With this command:

./manage.py runscript first --script-args=excel.xlsx

I get

No (valid) module for script 'first' found Try running with a higher verbosity level like: -v2 or -v3

I even tried running with higher verbosity level adding -v2 and -v3 at the end. But got this error:

No (valid) module for script 'first' found

I know that I am missing something simple, can anyone help me out?

Santosh Ghimire
  • 3,087
  • 8
  • 35
  • 63

2 Answers2

8

You need to run the script as follows:

/manage.py runscript scripts.syllabus.first --script-args=excel.xlsx

Here scripts and syllabus are two directories containing __init__.py.

Sudip Kafle
  • 4,286
  • 5
  • 36
  • 49
2

I dont have any experience with django. But the problem can be solved by adding syllabus to module lookup path. To do that add the following code in the __init__.py file under scripts directory.

import sys
import os

curr_path = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, curr_path + '/syllabus')

Or another way is to tell python that syllabus is a module itself. In that case you just need to rename first.py to __init__.py. You will then have to invoke it as

./manage.py runscript syllabus --script-args=excel.xlsx
Vishal
  • 1,199
  • 1
  • 8
  • 13
  • The first solution didn't work. But the second one worked. The problem I have with the second solution is that I have multiple scripts inside the syllabus folder. So, I need to change something for each time that I run the script. – Santosh Ghimire Aug 10 '15 at 09:49