tags:

views:

88

answers:

3

I've been developing a Django app for weeks locally on OSX 10.6.3. Recently, I rebooted my machine and went to start my development environment up.

Here's the error:

cm:myApp cm$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 11, in execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/init.py", line 360, in execute_manager
setup_environ(settings_mod)
File "/Library/Python/2.6/site-packages/django/core/management/init.py", line 343, in setup_environ
project_module = import_module(project_name)
File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module import(name)
ImportError: No module named myapp

I'm pretty new to Django / Python.

Digging around, it's possible that this might be due to MacPorts. Initially, I had a rough time getting Django up and running and I no longer remember if I'm using the Django from a MacPorts install or from easy_install. How do I tell? (I'd prefer not to reinstall everything).

Also, why is the camel casing in my app name gone in the ImportError message? When I search for "myapp" in my django project, I don't find it without camelcase anywhere.

And what causes MacPorts to work for a while but then break?

As a few other details, from settings.py:

INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'south', 'registration', 'pypaypal', 'notifier', 'myApp.batches', )

A: 

To tell where you're currently running Django from, open up a Python shell and do:

import django
print django.__path__

which should show you the path to the Django directory.

You might also want to do this from with the Python shell:

import sys
print sys.path

This should show you all the directories on the current PythonPath, which might help in your debugging.

Daniel Roseman
A: 

Okay, so this is very bizarre and I don't know what happened... but here's what fixed:

1) I open terminal and bash isn't recognizing any commands (python, vi, etc)
2) I restart machine, still not recognizing any commands
3) I look at my $PATH and /usr/bin is missing
4) I add /usr/bin to $PATH
5) I open vi and modify my profile to add /usr/bin
6) vi works, python works
7) python manage.py runserver works

How did /usr/bin get removed from my bash profile?

christmasgorilla
A: 

Recently got the same error again:

cm:myapp cm$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/init.py", line 436, in >execute_manager
setup_environ(settings_mod)
File "/Library/Python/2.6/site-packages/django/core/management/init.py", line 419, in >setup_environ
project_module = import_module(project_name)
File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module import(name)
ImportError: No module named myapp

This time, figured out that it was because python is case sensitive. myApp is actually camel case and it was looking for it as all lowercase. I changed the project name to all lowercase and got the following:

cm-2:myapp cm$ python manage.py runserver
Error: No module named myApp.appname

So that's no module with projectname.appname above. I went and changed my project name to all lowercase, then switched it back to camel case. And now the django dev server is running just fine.

This was quite confusing. Why did the case issue become a problem out of nowhere? Why did just simply changing the project name do anything? Did trying to run it with the name as lowercase instantiate it in any way?

christmasgorilla