ImportError: No module named myapp.modules

823 views
Skip to first unread message

Alex

unread,
Oct 1, 2014, 9:55:16 AM10/1/14
to web...@googlegroups.com

I've added a file to the modules folder, in a controller I import this module which works fine locally (Windows). When I deploy my application to the server (linux, apache) I get the following error when I try to import my module:

File "web2pypath/gluon/custom_import.py", line 82, in custom_importer
modules_prefix, globals, locals, [itemname], level)
ImportError: No module named myapp.modules

I did not activate the custom importer (track_changes) and there is a file __init__.py (which is empty) in the modules folder. Does someone have an idea what could be wrong or what I could try to fix this?


thanks, Alex

Leonel Câmara

unread,
Oct 1, 2014, 10:12:09 AM10/1/14
to web...@googlegroups.com
How are you importing the module?

Alex

unread,
Oct 1, 2014, 10:20:48 AM10/1/14
to web...@googlegroups.com

import jasperclient

jasperclient is the module name (there is a file modules/jasperclient.py).

Leonel Câmara

unread,
Oct 1, 2014, 10:53:01 AM10/1/14
to web...@googlegroups.com
After you deployed your application with the module in the modules folder, did you restart apache?

Alex

unread,
Oct 1, 2014, 10:59:34 AM10/1/14
to web...@googlegroups.com
not until now. Restarting apache didn't make any difference.

Leonel Câmara

unread,
Oct 1, 2014, 11:15:18 AM10/1/14
to web...@googlegroups.com
That's weird, it's normal to have to restart for web2py to detect new modules in the application, this should have solved the problem. How did you configure web2py and apache?

BTW if you're using Linux I seriously recommend a switch to nginx and uwsgi-emperor.

Leonel Câmara

unread,
Oct 1, 2014, 1:24:38 PM10/1/14
to web...@googlegroups.com
Another idea, delete all .pyc files in your modules folder. Restart apache and try again.

Alex

unread,
Oct 1, 2014, 4:43:09 PM10/1/14
to web...@googlegroups.com

thanks for your help. Unfortunately I could not resolve the issue so far. I deleted all .pyc files and restarted apache, still does not work (there are no .pyc files in the modules folder now). what web2py or apache configuration could have an effect on this? are there any specific settings? web2py runs in virtualenv, could this be related with the problem somehow? I've compiled the app on my machine and deploy the compiled app on the linux server. All the compiled files are in the dir 'compiled'.


maybe offtopic - but why should I switch to nginx? performance is great and our server load is hardly measurable.

Leonel Câmara

unread,
Oct 1, 2014, 8:46:26 PM10/1/14
to web...@googlegroups.com
You can not compile the app and deploy in another machine as pyc files are not portable. You should remove the compiled directory and compile it again on the server.
Then go to admin clear all sessions and cache.
Restart apache and try again.


As for nginx, I find that Apache and mod_wsgi are constantly creating strange and hard to find errors due to some arcane configuration option, also nginx is quite faster.


Alex

unread,
Oct 2, 2014, 4:12:59 AM10/2/14
to web...@googlegroups.com

Actually I'm doing exactly this (compile app on another machine) for years now without any problems (as long as I use the same Python and web2py version on both machines). So I would be surprised if this is the reason I cannot import the module. I tried to manually compile the files in the modules folder on the server but this didn't change anything.

How are the modules working for compiled apps? Because everything else (controllers, models, views) will be compiled and stored as .pyc file in the compiled dir. Are the module files compiled on demand (on import) directly in the modules folder?

Leonel Câmara

unread,
Oct 2, 2014, 6:44:26 AM10/2/14
to web...@googlegroups.com
Actually I'm doing exactly this (compile app on another machine) for years now without any problems (as long as I use the same Python and web2py version on both machines). So I would be surprised if this is the reason I cannot import the module. I tried to manually compile the files in the modules folder on the server but this didn't change anything.

Well pyc files are python version specific, if you use exactly the same version it may work, I still wouldn't recommend it as there's no good reason to do it.

Are the module files compiled on demand (on import) directly in the modules folder?
 
Yes.


Alex

unread,
Oct 22, 2014, 12:26:27 PM10/22/14
to web...@googlegroups.com
finally I could solve the problem. The __init__.py file was missing in the application folder ( __init__.py file in modules folder was already there so I thought that would be enough).
Reply all
Reply to author
Forward
0 new messages