Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web2py doesn't recognize modules in the modules directory

Tags:

python

web2py

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?

like image 351
SUB0DH Avatar asked May 10 '26 19:05

SUB0DH


1 Answers

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.

like image 67
SUB0DH Avatar answered May 13 '26 10:05

SUB0DH