I am attempting to create console scripts which can be run by a scheduled
task or manually which requires import of custom modules. My python script
is located in the applications/[appname]/private folder.
In a very simple example of the issue Ive run the following command
python web2py.py -S testapp -N -R applications/testapp/private/test.py
test.py looks like this
from mymodule import test
print test()
and mymodule which is located in applications/testapp/modules/mymodule.py
looks like tis
def test():
return 1
However custom_import.py is throwing me an ImportError exception.
Traceback (most recent call last):
> File "/root/web2py-v2/gluon/shell.py", line 217, in run
> execfile(startfile, _env)
> File "applications/testapp/private/test.py", line 2, in <module>
> from mymodule import test
> File "/root/web2py-v2/gluon/custom_import.py", line 300, in __call__
> fromlist, level)
> File "/root/web2py-v2/gluon/custom_import.py", line 80, in __call__
> level)
> ImportError: No module named mymodule
My understanding is that the -R param creates a web2py environment (much
like it does with controller files) and should be able to import this
module. What I can do is import the module using the full path that is
from applications.testapp.modules.mymodule import test
However when the application goes live, the application name may change. Is
there a way to import like I currently do in controllers, or must I use the
full path like the above ?
Im currently using Version 1.99.4 (2011-12-14 14:46:14), but have also
tested with Version 2.0.9 (2012-09-13 23:51:30) stable
--