Where to put standalone-django scripts without breaking imports?

Viewed 4701

I'm still pretty new to Python.

I have a Django website with several apps and a /libs directory. I need to add a couple cron jobs that will use my Django models. I've already worked all that out, no big deal.

I have a problem with my imports, though.

I would like to include these scripts in the App they generally belong-to. But when I execute the script from the commandline, it's unable to load modules from the /libs directory.

To illustrate specifically the dir structure, imagine this pseudo-code:

import ./../libs/mysharedlib.py   

In other words the scripts and sharedlib are:

~/project/myapp/myscript.py

~/project/libs/mysharedlib.py

I get that I could just add ~/project to my PYTHONPATH but then I have to worry about doing this during deployment and it just feels broken.

Should I move my scripts out of my apps and put them in the ~/project? Is there a better way?

1 Answers
Related