So, I’ve got this set-up in which I installed a django project (the directory containing the settings.py and manage.py) in the site-packages directory of my python installation. I’ve done this to use apps from other packages, which works nicely.
I noticed however, that when I’m developing, the development server (manage.py runserver) loads files from the site-package directory.
Example:
There is a file, views.py, that loads models from models.py using:
from models import Project, Test
Because of a small error within the production code I tried to fix, still pops up within the development server, and the django error page (such a nice feature) shows the old code from the file that’s installed in site-packages. So, I put in this line:
import models
print models.__file__
and the result of that is exactly the file I want, from my development directory. The next line, from models import Project, Test loads models from the site-package directory, which is totally not what I want.
I guess I’ve polluted the namespace, I’m guessing that the from-import imports already loaded imports from memory, but that the normal import-line imports a module that isn’t in memory yet. This apparently leads to the strange effect of being successfully able to change views.py and see the changes in the development server.
Anybody’s got any idea how to fix this?
System info:
- Python2.7
- Django1.3
- Debian
This is what virtualenv is for. It creates isolated development environments, and is indispensable for working on multiple projects/versions at once.