So, I configured virtualenv on Ubuntu, installed everything and got the development site with runserver . All my own unit tests passed, but many unit tests of Django packages did not pass.
So, I tried to do git bisect to figure this out by checking the earliest commits I made. I went too early in history when the development environment used different database engines, packages, etc., And the site, of course, could not work. Then I decided to work on something even more important than the failed Django unit tests (since my own worked), and so I returned to the last commit in the development branch.
I started runserver again, but this time, when I reloaded the homepage, I was met with an error:
Traceback: File "...venv.../local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 101. request.path_info) File "...venv.../local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve 298. for pattern in self.url_patterns: File "...venv.../local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns 328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "...venv.../local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module 323. self._urlconf_module = import_module(self.urlconf_name) File "...venv.../local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module 35. __import__(name) File "...project dir.../myproject/urls.py" in <module> 2. import frontpage.views Exception Type: ImportError at / Exception Value: No module named views
Everything worked fine before I tried using git bisect. But no more, at least on my local machine.
So, I googled around and changed my ROOT_URLCONF from 'myproject.urls' to just 'urls' . Now I get this error message:
Traceback: File "...venv.../local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 101. request.path_info) File "...venv.../local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve 298. for pattern in self.url_patterns: File "...venv.../local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns 328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "...venv.../local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module 323. self._urlconf_module = import_module(self.urlconf_name) File "...venv.../local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module 35. __import__(name) Exception Type: ImportError at / Exception Value: No module named urls
I searched a little more Google and thought that my path to Python does not include my project directory ... but no, this completely happens when I included print sys.path in my settings.py file for the project!
So what's the problem? I am using Django 1.4.3 and starting the server using python manage.py runserver . I swear my site only worked a few hours ago, and since then I have done git checkout development and git reset many times ... I tried to remove virtualenv, recreate it and reinstall all the Python packages. I am still getting the same error.
(Also, I activated virtualenv, and I even tried restarting, just in case ... until I got lucky)
UPDATE
Following Lennart's suggestion, I started the debugger right before the failed import and found that import frontpage works, but not import frontpage.views , frontpage.tests or anything else. I have a __init__.py file in the frontpage directory. At the moment, sys.path contains my project folder, everything is correct ...
I have already included frontpage in my INSTALLED_APPS .
Fixed
Thanks to Lennart, I verified that the frontpage module is indeed being imported correctly. The correct .pyc file was shown, but that made me wonder if the pyc files were somehow out of sync with my actual code.
So, I deleted all the pyc files, restarted the server, and everything works fine again :)