Django 1.5, Apache, wsgi.py - ImportError: Could not import settings -
i have seen others post on over stackoverflow (mainly django 1.4), none of provided successful solution me.
i unable setup django 1.5.1 correctly apache. receive following error:
"importerror: not import settings 'foobar.settings' (is on sys.path?): no module named foobar.settings"
using fresh install of xubuntu 13.04 on virtualbox.
here setup script
$ sudo apt-get update $ sudo apt-get install apache2 $ sudo apt-get install libapache2-mod-wsgi $ sudo apt-get install python-setuptools $ sudo apt-get install build-essential nmap python-dev $ sudo easy_install pip $ sudo pip install virtualenvwrapper $ cd ~ $ vim .bashrc export workon_home=$home/.virtualenvs export project_home=$home/foobar.com source /usr/local/bin/virtualenvwrapper.sh # save .bashrc $ . .bashrc $ mkdir -p foobar.com/prod $ cd foobar.com/prod # start python project virtualenv $ mkvirtualenv foobar --no-site-packages $ workon foobar $ pip install django # create project root $ django-admin.py startproject foobar vim foobar/foobar/settings.py # add database settings settings.py databases = { 'default': { 'engine': 'django.db.backends.sqlite3', 'name': '/home/banjo/foobar.com/prod/foobar/foobar/foobar.db' } } # save settings.py $ cd /home/banjo/foobar.com/prod/foobar python manage.py syncdb # create directory static files $ mkdir static # create directory apache log files $ cd /home/banjo/foobar.com/prod $ mkdir logs $ pip freeze > requirements.txt # create apache .conf file site $ sudo vim /etc/apache2/sites-available/foobar.conf <virtualhost *:80> serveradmin banjo@foobar.com servername foobar serveralias foobar alias /static/ /home/banjo/foobar.com/prod/foobar/static/ <directory /home/banjo/foobar.com/prod/foobar/static> order allow,deny allow </directory> loglevel warn errorlog /home/banjo/foobar.com/prod/logs/apache_error.log customlog /home/banjo/foobar.com/prod/logs/apache_access.log combined wsgidaemonprocess foobar threads=15 display-name=%{group} python-path=/home/banjo/foobar.com/prod/foobar/foobar:/home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages wsgiprocessgroup foobar wsgiscriptalias / /home/banjo/foobar.com/prod/foobar/foobar/wsgi.py </virtualhost> # save .conf file # add site /etc/hosts $ vim /etc/hosts 127.0.0.1 foobar # save hosts file # configure .wsgi file , following $ vim /home/banjo/foobar.com/prod/foobar/foobar/wsgi.py import sys path = '/home/banjo/foobar.com/prod/foobar/foobar' if path not in sys.path: sys.path.insert(0, '/home/banjo/foobar.com/prod/foobar/foobar') # save wsgi.py $ sudo a2ensite foobar.conf $ sudo service apache2 restart # open browser , navigate site http://foobar here directory tree
+-- foobar.com ¦ +-- prod ¦ +-- foobar ¦ ¦ +-- foobar ¦ ¦ ¦ +-- foobar.db ¦ ¦ ¦ +-- __init__.py ¦ ¦ ¦ +-- __init__.pyc ¦ ¦ ¦ +-- settings.py ¦ ¦ ¦ +-- settings.pyc ¦ ¦ ¦ +-- urls.py ¦ ¦ ¦ +-- wsgi.py ¦ ¦ +-- manage.py ¦ ¦ +-- static ¦ +-- logs ¦ ¦ +-- apache_access.log ¦ ¦ +-- apache_error.log ¦ +-- requirements.txt here full error log
[tue may 21 14:02:34 2013] [error] [client 127.0.0.1] mod_wsgi (pid=3424): exception occurred processing wsgi script '/home/banjo/foobar.com/prod/foobar/foobar/wsgi.py'. [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] traceback (most recent call last): [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] file "/home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in call [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] self.load_middleware() [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] file "/home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages/django/core/handlers/base.py", line 45, in load_middleware [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] middleware_path in settings.middleware_classes: [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] file "/home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages/django/conf/init.py", line 53, in getattr [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] self._setup(name) [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] file "/home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages/django/conf/init.py", line 48, in _setup [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] self._wrapped = settings(settings_module) [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] file "/home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages/django/conf/init.py", line 134, in init [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] raise importerror("could not import settings '%s' (is on sys.path?): %s" % (self.settings_module, e)) [tue may 21 14:02:34 2013] [error] [client 127.0.0.1] importerror: not import settings 'foobar.settings' (is on sys.path?): no module named foobar.settings here output of sys path
(foobar)banjo@sandbox:~/foobar.com$ python python 2.7.4 (default, apr 19 2013, 18:32:33) [gcc 4.7.3] on linux2 type "help", "copyright", "credits" or "license" more information. >>> import sys >>> path in sys.path: print path ... /home/banjo/.virtualenvs/foobar/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg /home/banjo/.virtualenvs/foobar/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg /home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg /home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg /home/banjo/.virtualenvs/foobar/lib/python2.7 /home/banjo/.virtualenvs/foobar/lib/python2.7/plat-i386-linux-gnu /home/banjo/.virtualenvs/foobar/lib/python2.7/lib-tk /home/banjo/.virtualenvs/foobar/lib/python2.7/lib-old /home/banjo/.virtualenvs/foobar/lib/python2.7/lib-dynload /usr/lib/python2.7 /usr/lib/python2.7/plat-i386-linux-gnu /usr/lib/python2.7/lib-tk /home/banjo/.virtualenvs/foobar/local/lib/python2.7/site-packages /home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages
try adding following python path, making appropriate path substitution.
/unix/path/above/foobar/foobar.com/prod/foobar/ one way add path create file called foobar.pth (or whatever.pth) , place in following directory:
/home/banjo/.virtualenvs/foobar/lib/python2.7/site-packages that file should contain newline separated list of paths want add virtual environment.
/unix/path/above/foobar/foobar.com/prod/foobar/ update: might path entry make:
/unix/path/above/foobar/foobar.com/prod/foobar/foobar/ adding path here has added benefit of exposing path python interpreter , not through wsgi.py script.
Comments
Post a Comment