I copied a module to the "modules" folder of the application in web2py. When I tried to import the module in any function inside of any of the controllers, I get the following error:
<type 'exceptions.ImportError'> No module named module_name
I get that error irrespective of any module used. But if I copied the same module to the "site-packages" and import it, it works perfectly.
I found out that the "sys.path" doesn't contain the modules folder but contains the "site-packages" folder.
How do I add the modules folder to "sys.path" specific for web2py or are there any other ways to solve this problem?
Finally found a solution to my problem.
Seems like in order to import a module in the module directory using import module_name, the name of the application must be in all lower case.
Previously, the name of my application was projectX, but when I changed it to projectx the import module_name worked like it should.
I also found out that explicitly stating the application name while importing the module also works, no matter how the application name is. import applications.projectX.modules.module_name also worked for me when the name of the application was projectX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With