Forums

import error cannot find my forms module

Not sure why it cant import my forms module? It works locally but not when I upload it here. Any ideas?

2014-02-12 12:32:09,229 :Traceback (most recent call last):
2014-02-12 12:32:09,230 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-02-12 12:32:09,231 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-02-12 12:32:09,231 :  File "/usr/lib/python3.3/logging/__init__.py", line 1269, in exception
2014-02-12 12:32:09,232 :    self.error(msg, *args, **kwargs)
2014-02-12 12:32:09,232 :  File "/usr/lib/python3.3/logging/__init__.py", line 1262, in error
2014-02-12 12:32:09,232 :    self._log(ERROR, msg, args, **kwargs)
2014-02-12 12:32:09,233 :  File "/usr/lib/python3.3/logging/__init__.py", line 1368, in _log
2014-02-12 12:32:09,233 :    self.handle(record)
2014-02-12 12:32:09,233 :  File "/usr/lib/python3.3/logging/__init__.py", line 1377, in handle
2014-02-12 12:32:09,234 :    if (not self.disabled) and self.filter(record):
2014-02-12 12:32:09,234 :  File "/usr/lib/python3.3/logging/__init__.py", line 687, in filter
2014-02-12 12:32:09,235 :    for f in self.filters:
2014-02-12 12:32:09,235 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-02-12 12:32:09,235 :    app_iterator = self.app(environ, start_response)
2014-02-12 12:32:09,235 :  File "/bin/user_wsgi_wrapper.py", line 73, in import_error_application
2014-02-12 12:32:09,235 :    raise e
2014-02-12 12:32:09,235 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-02-12 12:32:09,236 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-02-12 12:32:09,236 :  File "/usr/lib/python3.3/logging/__init__.py", line 1269, in exception
2014-02-12 12:32:09,237 :    self.error(msg, *args, **kwargs)
2014-02-12 12:32:09,237 :  File "/usr/lib/python3.3/logging/__init__.py", line 1262, in error
2014-02-12 12:32:09,237 :    self._log(ERROR, msg, args, **kwargs)
2014-02-12 12:32:09,238 :  File "/usr/lib/python3.3/logging/__init__.py", line 1368, in _log
2014-02-12 12:32:09,239 :    self.handle(record)
2014-02-12 12:32:09,239 :  File "/usr/lib/python3.3/logging/__init__.py", line 1377, in handle
2014-02-12 12:32:09,239 :    if (not self.disabled) and self.filter(record):
2014-02-12 12:32:09,240 :  File "/usr/lib/python3.3/logging/__init__.py", line 687, in filter
2014-02-12 12:32:09,240 :    for f in self.filters:
2014-02-12 12:32:09,240 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-02-12 12:32:09,240 :    app_iterator = self.app(environ, start_response)
2014-02-12 12:32:09,240 :  File "/bin/user_wsgi_wrapper.py", line 73, in import_error_application
2014-02-12 12:32:09,241 :    raise e
2014-02-12 12:32:09,241 :  File "/bin/user_wsgi_wrapper.py", line 82, in <module>
2014-02-12 12:32:09,241 :    application = load_wsgi_application()
2014-02-12 12:32:09,241 :  File "/bin/user_wsgi_wrapper.py", line 78, in load_wsgi_application
2014-02-12 12:32:09,241 :    return __import__(os.environ['WSGI_MODULE'], globals(), locals(), ['application']).application
2014-02-12 12:32:09,241 :  File "/var/www/rcham_pythonanywhere_com_wsgi.py", line 16, in <module>
2014-02-12 12:32:09,242 :    from addressbook.app import app as application
2014-02-12 12:32:09,242 :  File "/home/rcham/mysite/addressbook/app.py", line 4, in <module>
2014-02-12 12:32:09,243 :    from forms import LoginForm, ContactsForm
2014-02-12 12:32:09,243 :ImportError: No module named 'forms'

[edited by admin: formatting]

Without looking at your files I can't be sure, but I suspect that you have /home/rcham/mysite/ on the sys.path in your WSGI file. That means that if you want to import stuff from the module in /home/rcham/mysite/addressbook/forms.py, you should do

from addressbook.forms import LoginForm, ContactsForm

instead of

from forms import LoginForm, ContactsForm

If you don't want to change your code, an alternative is to edit your WSGI file and change the path that you add to sys.path to /home/rcham/mysite/addressbook/

thanks, I think that fixed it

Excellent, thanks for letting us know!