0

I'm setting up a local dev environment in a vagrant box I've configured for django projects. As such, virtualenv is really not too much use at this point, so I'm just installing everything in requirements.txt with the modules

Django==1.7.3
Pillow==2.7.0
django-angular==0.7.10
djangorestframework
markdown
django-filter
mysqlclient==1.3.4

My issue is that no matter what I've tried, I consistently get

Traceback (most recent call last):
File "/home/vagrant/photoapp.com/photoapp/wsgi.py", line 17, in <module>
from django.core.wsgi import get_wsgi_application
   ImportError: No module named 'django'

The application folder structure is:

photoapp.com/
├── app
│   ├── admin.py
│   ├── __init__.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── manage.py
├── photoapp
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── requirements.txt
├── templates
└── Vagrantfile

with a standard wsgi.py:

import os
import sys

sys.path.append("/home/vagrant/photoapp.com")
sys.path.append("/home/vagrant/photoapp.com/photoapp")

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "photoapp.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

and a virtualhost file:

<VirtualHost *:80>
    ServerName      dev.photoapp.com
    ServerAlias     photoapp.com

    DocumentRoot    "/home/vagrant/photoapp.com"

    alias /photos/  "/home/vagrant/photos/"
    alias /static/  "/home/vagrant/photoapp.com/static/"

    <Directory /home/vagrant/photoapp.com/static>
            Require all granted
    </Directory>

    <Directory /home/vagrant/photos>
            Require all granted
    </Directory>

    <Directory /home/vagrant/photoapp.com/photoapp>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

    ErrorLog        /home/vagrant/logs/error.log
    CustomLog       /home/vagrant/logs/access.log combined

    WSGIScriptAlias / /home/vagrant/photoapp.com/photoapp/wsgi.py


</VirtualHost>

But each time I access the site via dev.photoapp.com (hosts file has been modified), I get the error 500 and the traceback message above.

Note that

  1. import django works from inside a python shell
  2. `python manage.py runserver loads up fine with url 127.0.0.1:8000
  3. sys.path prints out:

    ['', '/usr/bin', '/usr/local/lib/python2.7/dist-packages/django', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/IPython/extensions']

So I can see that the django packages are accessible on the path. But it's not resolving with Apache access.

Any ideas?

1 Answer 1

1

try adding:

WSGIPythonPath /home/vagrant/photoapp.com

at the top of your virtualhost config file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.