Forums

Can't load project (that worked on home computer)

Well my current project is simply bugging out on pythonanywhere. While it worked perfectly on my home pc.

The github location: https://github.com/pulli23/IFoxHuntGameSite

When I finally got around to set up everything correct (basically I used the wizard to create a new "app" called "IFoxHuntGameSite", then delete the main folder and finally cloned github), an error occurred when 'reloading website':

2015-12-04 12:59:20,512 :Traceback (most recent call last):
2015-12-04 12:59:20,513 :  File "/usr/local/lib/python3.4/dist-packages/django/utils/module_loading.py", line 21, in import_by_path
2015-12-04 12:59:20,513 :    module = import_module(module_path)
2015-12-04 12:59:20,513 :  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
2015-12-04 12:59:20,513 :    return _bootstrap._gcd_import(name[level:], package, level)
2015-12-04 12:59:20,514 :  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
2015-12-04 12:59:20,518 :  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
2015-12-04 12:59:20,518 :  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
2015-12-04 12:59:20,518 :ImportError: No module named 'django.middleware.security'
2015-12-04 12:59:20,518 :
2015-12-04 12:59:20,518 :During handling of the above exception, another exception occurred:
2015-12-04 12:59:20,519 :
2015-12-04 12:59:20,519 :Traceback (most recent call last):
2015-12-04 12:59:20,519 :  File "/bin/user_wsgi_wrapper.py", line 134, in __call__
2015-12-04 12:59:20,519 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-12-04 12:59:20,519 :  File "/usr/lib/python3.4/logging/__init__.py", line 1310, in exception
2015-12-04 12:59:20,519 :    self.error(msg, *args, **kwargs)
2015-12-04 12:59:20,520 :  File "/usr/lib/python3.4/logging/__init__.py", line 1303, in error
2015-12-04 12:59:20,520 :    self._log(ERROR, msg, args, **kwargs)
2015-12-04 12:59:20,520 :  File "/usr/lib/python3.4/logging/__init__.py", line 1409, in _log
2015-12-04 12:59:20,521 :    self.handle(record)
2015-12-04 12:59:20,521 :  File "/usr/lib/python3.4/logging/__init__.py", line 1418, in handle
2015-12-04 12:59:20,521 :    if (not self.disabled) and self.filter(record):
2015-12-04 12:59:20,521 :  File "/usr/lib/python3.4/logging/__init__.py", line 706, in filter
2015-12-04 12:59:20,522 :    for f in self.filters:
2015-12-04 12:59:20,522 :  File "/bin/user_wsgi_wrapper.py", line 126, in __call__
2015-12-04 12:59:20,522 :    app_iterator = self.app(environ, start_response)
2015-12-04 12:59:20,522 :  File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/wsgi.py", line 187, in __call__
2015-12-04 12:59:20,522 :    self.load_middleware()
2015-12-04 12:59:20,523 :  File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 45, in load_middleware
2015-12-04 12:59:20,523 :    mw_class = import_by_path(middleware_path)
2015-12-04 12:59:20,523 :  File "/usr/local/lib/python3.4/dist-packages/django/utils/module_loading.py", line 26, in import_by_path
2015-12-04 12:59:20,523 :    sys.exc_info()[2])
2015-12-04 12:59:20,523 :  File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 549, in reraise
2015-12-04 12:59:20,523 :    raise value.with_traceback(tb)
2015-12-04 12:59:20,524 :  File "/usr/local/lib/python3.4/dist-packages/django/utils/module_loading.py", line 21, in import_by_path
2015-12-04 12:59:20,524 :    module = import_module(module_path)
2015-12-04 12:59:20,524 :  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
2015-12-04 12:59:20,524 :    return _bootstrap._gcd_import(name[level:], package, level)
2015-12-04 12:59:20,524 :  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
2015-12-04 12:59:20,524 :  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
2015-12-04 12:59:20,524 :  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
2015-12-04 12:59:20,525 :django.core.exceptions.ImproperlyConfigured: Error importing module django.middleware.security: "No module named 'django.middleware.security'"

This error did not occur at all in my home project, what is the difference? At home I use django 1.9 btw?

You're not using Django 1.9 on PythonAnywhere because you haven't created a virtualenv with DJango 1.9 installed. Instruction here

Well adding a virtual environment solved "this" problem. However there are quite a few new problems:

2015-12-04 15:37:52,655 :django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
2015-12-04 15:37:52,896 :Traceback (most recent call last):
2015-12-04 15:37:52,896 :  File "/bin/user_wsgi_wrapper.py", line 134, in __call__
2015-12-04 15:37:52,897 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-12-04 15:37:52,897 :  File "/usr/lib/python3.4/logging/__init__.py", line 1310, in exception
2015-12-04 15:37:52,897 :    self.error(msg, *args, **kwargs)
2015-12-04 15:37:52,897 :  File "/usr/lib/python3.4/logging/__init__.py", line 1303, in error
2015-12-04 15:37:52,898 :    self._log(ERROR, msg, args, **kwargs)
2015-12-04 15:37:52,898 :  File "/usr/lib/python3.4/logging/__init__.py", line 1409, in _log
2015-12-04 15:37:52,899 :    self.handle(record)
2015-12-04 15:37:52,899 :  File "/usr/lib/python3.4/logging/__init__.py", line 1418, in handle
2015-12-04 15:37:52,899 :    if (not self.disabled) and self.filter(record):
2015-12-04 15:37:52,899 :  File "/usr/lib/python3.4/logging/__init__.py", line 706, in filter
2015-12-04 15:37:52,900 :    for f in self.filters:
2015-12-04 15:37:52,900 :  File "/bin/user_wsgi_wrapper.py", line 126, in __call__
2015-12-04 15:37:52,900 :    app_iterator = self.app(environ, start_response)
2015-12-04 15:37:52,900 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 158, in __call__
2015-12-04 15:37:52,901 :    self.load_middleware()
2015-12-04 15:37:52,901 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/core/handlers/base.py", line 51, in load_middleware
2015-12-04 15:37:52,901 :    mw_class = import_string(middleware_path)
2015-12-04 15:37:52,902 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/utils/module_loading.py", line 20, in import_string
2015-12-04 15:37:52,902 :    module = import_module(module_path)
2015-12-04 15:37:52,902 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/importlib/__init__.py", line 109, in import_module
2015-12-04 15:37:52,902 :    return _bootstrap._gcd_import(name[level:], package, level)
2015-12-04 15:37:52,902 :  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
2015-12-04 15:37:52,903 :  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
2015-12-04 15:37:52,903 :  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
2015-12-04 15:37:52,903 :  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
2015-12-04 15:37:52,903 :  File "<frozen importlib._bootstrap>", line 1129, in _exec
2015-12-04 15:37:52,904 :  File "<frozen importlib._bootstrap>", line 1471, in exec_module
2015-12-04 15:37:52,904 :  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
2015-12-04 15:37:52,904 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
2015-12-04 15:37:52,905 :    from django.contrib.auth.backends import RemoteUserBackend
2015-12-04 15:37:52,905 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/contrib/auth/backends.py", line 4, in <module>
2015-12-04 15:37:52,905 :    from django.contrib.auth.models import Permission
2015-12-04 15:37:52,905 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/contrib/auth/models.py", line 4, in <module>
2015-12-04 15:37:52,906 :    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
2015-12-04 15:37:52,906 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
2015-12-04 15:37:52,907 :    class AbstractBaseUser(models.Model):
2015-12-04 15:37:52,907 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/db/models/base.py", line 94, in __new__
2015-12-04 15:37:52,908 :    app_config = apps.get_containing_app_config(module)
2015-12-04 15:37:52,908 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
2015-12-04 15:37:52,909 :    self.check_apps_ready()
2015-12-04 15:37:52,909 :  File "/home/paul23/.virtualenvs/django19/lib/python3.4/site-packages/django/apps/registry.py", line 124, in check_apps_ready
2015-12-04 15:37:52,911 :    raise AppRegistryNotReady("Apps aren't loaded yet.")

This might be even more cryptic? Google reveals this is often a problem with the wsgi.py file. So when I go to /home/paul23/IFoxHuntGameSite/IFoxHuntGameSite/wsgi.py I do have:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "IFoxHuntGameSite.settings")

application = get_wsgi_application()

Which is correct right? Or am I missing a major problem?

You're not setting sys.path in the WSGI file. Look at the end of this under Django-specific issues and see if that helps.

I have to state I got nothing from that tutorial. Adding the lines:

import sys
path = "/home/paul23/IFoxHuntGameSite"
if path not in sys.path:
    sys.path.append(path)
os.environ["DJANGO_SETTINGS_MODULE"] = "IFoxHuntGameSite/settings.py"

To wsgi.py does not solve anything. - the page is also very cryptic with some syntax errors.

I think Glenn meant the PythonAnywhere WSGI file that's linked from the "Web" tab, in the "Code" section. The error you're getting suggests that your current WSGI file has the code for a Django < 1.7 app, and your app is actually a more recent version (1.9?)

Ah thanks giles (and glenn) - I'm now looking at the WSGI file in the web tab....

..... And there I notice a handy comment ("If using django 1.7 and above comment out those two lines....") which solved it. Kind of hidden "config" flag though.

Yup, it's a tricky one for us to work around. We're working towards a system where we can more easily upgrade all Django versions to 1.7 or higher for all versions of Python, and when we've done that it shouldn't be necessary.

Is everything working OK now?

Well yes, played my "game" (it was a simple gps-based game based on old fashioned hide and seek). Only I seem to have (unrelated) broken my error.log.

I'm sure we can figure it out, even if it's unrelated! What's broken about the error log?