1
votes

I am trying to pick up an old Django project and my immediate goal is to see what I can get running on my computer on the development server. I get:

Inner Sanctum ~/pragmatometer $ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in 
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    commands = get_commands()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
    apps = settings.INSTALLED_APPS
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 49, in _setup
    self._wrapped = Settings(settings_module)
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 132, in __init__
    % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'pragmatometer.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named pragmatometer.settings

Here is some command line output:

Inner Sanctum ~/pragmatometer $ /bin/pwd
/Users/jonathan/pragmatometer
Inner Sanctum ~/pragmatometer $ echo $PYTHONPATH
/Users/jonathan
Inner Sanctum ~/pragmatometer $ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pragmatometer
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named pragmatometer
>>> import pragmatometer.settings
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named pragmatometer.settings
>>> 

What should I be doing that I'm not? (Or, as it was an older project, should I just start with a fresh new project?)

Thanks,

3
Is the pragmatometer directory a package (does it have a __init__.py file) and is there a settings module somewhere inside there (does it have a settings.py file)?Wander Nauta
ls *.py output: init.py manage.py settings.py views.py functions.py models.py urls.pyChristos Hayward
And if you try to import pragmatometer.settings from ~?Wander Nauta

3 Answers

0
votes

every django project comes with a settings.py file, and django will refuse to run, or load models, until that settings.py file is loaded.

settings.py file needs to be in a module and part of your current PYTHONPATH, and env. variable DJANGO_SETTINGS_MODULE should be set to it.

For example:

# assuming your file is under /myproject/mywebsite/settings.py
export PYTHONPATH=/myproject/
export DJANGO_SETTINGS_MODULE=mywebsite.settings
0
votes

A Django project normally looks something like this (as of Django 1.4 and above, I think).

myproject
    myproject
        __init__.py
        settings.py
    app1
    app2

You can look around online for examples and variations on this.

Note that there's a myproject directory, containing settings, under the top-level myproject.

Does yours look at all like this?

Or did you originally target an older version of Django that uses a different layout?

If you try to do this:

PYTHONPATH=/Users/jonathan python
import pragmatometer

like in your second code block, it's going to treat /Users/jonathan as a Python package and look for /Users/jonathan/__init__.py, which probably doesn't exist), so it won't check /Users/jonathan/pragmatometer/settings.py.

0
votes

I found the culprit, or at least a culprit. I had omitted (in my .bashrc) the "export ", and now I'm on to another problem.