views:

68

answers:

2

I have a python/django application that runs on the google app engine.

My views.py file has some imports...

from commands.userCommands import RegisterUserCommand
from commands.accountCommands import CreateNewAccountCommand, RenameAccountCommand

These imports work fine on my development environment (local machine). But when I upload to the google app engine, views.py fails with a "Could not import views. Error was: No module named userCommands" error.

Any idea why I can't import my commands.userCommands module?

My file structure looks as follows...

- app.yaml
- urls.py
- views.py
- etc...
- commands/__init__.py
- commands/userCommands.py

Note: I did try to append my application name to the module name/path. No luck.

Note: I did do an update with the --noisy argument, and it does appear to upload my commands folder successfully.

+2  A: 

The __init__.py files are required to make Python treat the directories as containing packages, so you need a

commands/__init__.py

file in your directory structure. See http://docs.python.org/tutorial/modules.html.

Raphink
Thanks Raphink. Sorry, should have mentioned... I do have an __init__.py file in that folder. Will clarify the question...
willem
+5  A: 

You could be running into a clash with Python's own commands module (which doesn't have submodules like yours) -- naming your own modules and packages in ways that are meant to hide ones in the standard library (just like naming your variables in ways that are meant to hide builtin names, like list or file) is always a perilous undertaking, even though it "should" work there's always potential for confusion.

Could you try renaming that commands package and its uses to something unambiguous and free from danger, such as mycommands, and see if that just makes the problem disappear? If that's the case you can then open a ticket on GAE's tracker (because it would show a minor but undeniable bug in GAE's runtime) but meanwhile your problem is solved!-) If the problem stays, ah well, at least we've eliminated one likely cause and can keep digging...

Alex Martelli
I didn't realize python had a commands module. Thanks Alex, I'll try renaming my package and see what happens.
willem
Works like a charm, thanks Alex.
willem