I'm developing application on Django, and ready to move to deployment server. I'm able to run a new django project on apache(I can see the welcome page).
However, when I copy my original project's files to apache project directory, I start getting errors. Here is a sample from apache/error.log.
[Wed Jan 26 19:22:08 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught ImportError while rendering: No module named charts
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] mod_wsgi (pid=4670): Exception occurred processing WSGI script '/srv/www/enpass/apache/django.wsgi'.
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] response = self.get_response(request)
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 141, in get_response
My django.wsgi file looks like
import os
import sys
path = '/srv/www'
if path not in sys.path:
sys.path.insert(0, '/srv/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'enpass.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I've changed all the paths in files to suit the new directory structure, so I'm pretty sure thats not the problem. FIY, I followed the steps given in this tutorial http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/
I figured it out myself. We need to add the project directory path to sys.path. The following code solved the problem in django.wsgi
path = '/srv/www/enpass'
if path not in sys.path:
sys.path.append(path)
Looks like you are missing the charts module..
install pip
sudo easy_install pip
list packages
pip freeze
do the same on the development machine and look for a chart module, then install it on the production server with
sudo pip install <packagename>
Related
I am trying to deploy mayan-edms a django web application on a RedHat5.6 server in production mode with apache webserver.
I have setup the database and the used a virtual-env to setup the env
This is my httpd.conf
WSGIScriptAlias /mayan /var/www/mayan/mayan/wsgi/dispatch.wsgi
WSGIPythonPath /var/www/mayan/mayan:/var/www/mayan/lib/python2.6/site-packages
<Directory /var/www/mayan/mayan>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
I am getting a 500 error if I start apache with this conf. Could anyone tell me where it is getting misconfigured?
This is the error
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] mod_wsgi (pid=21715): Exception occurred processing WSGI script '/var/www/mayan/mayan/wsgi/dispatch.wsgi'.
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] Traceback (most recent call last):
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] File "/var/www/mayan/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] self.load_middleware()
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] File "/var/www/mayan/lib/python2.6/site-packages/django/core/handlers/base.py", line 45, in load_middleware
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] mod = import_module(mw_module)
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] File "/var/www/mayan/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] __import__(name)
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] File "/var/www/mayan/mayan/apps/common/__init__.py", line 17
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] from .conf.settings import (AUTO_CREATE_ADMIN, AUTO_ADMIN_USERNAME,
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] ^
[Mon Jan 14 12:47:02 2013] [error] [client 130.229.146.48] SyntaxError: invalid syntax
This is my init.py around line 17
from django.db import transaction, DatabaseError
from navigation.api import register_links, register_top_menu
from .conf.settings import (AUTO_CREATE_ADMIN, AUTO_ADMIN_USERNAME, AUTO_ADMIN_PASSWORD, TEMPORARY_DIRECTORY)
from .conf import settings as common_settings
from .utils import validate_path
from .models import AutoAdminSingleton
Sounds like a Python version issue. RHEL 5.6 appears to be quite an old release, and anyway Red Hat are known for bundling old versions of Python. Looking at this table it seems likely that that version of RHEL was not even Python 2.4.
From the other side, the minimum Python version to run the current Django release is 2.7. Although that said, the requirements.txt file for your app actually asks for Django 1.3.5 - but you will still need at least Python 2.6 for that. You will either need to compile and install that version yourself, or upgrade your version of Red Hat.
You are using python 2.6, the documentation for installation seems to use python 2.7
I'm setting up a django server (1.4, python 2.7) with apache2 + mod_wsgi on a Debian system. From the django side, everything works perfect, if I run manage.py runserver, the development server displays the site correctly, however, when I try to set up my apache server to run WSGI, it fails displaying a ValueError.
This is mysite.wsgi
ALLDIRS = ['/usr/local/lib/python2.7/site-packages']
# the above directory depends on the location of your python installation.
# if using virtualenv, it will need to match your projects locale.
import os
import sys
import site
os.environ['DJANGO_SETTINGS_MODULE'] = 'ggDatabase.settings'
prev_sys_path = list(sys.path)
sys.path.append("/usr/local/lib/python2.7")
path = "/home/acad/statsdb/src"
if path not in sys.path:
sys.path.append(path)
sys.path.append("/home/acad/statsdb/src/ggDatabase")
for directory in ALLDIRS:
site.addsitedir(directory)
new_sys_path = []
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
# change this depending on your project.
site.addsitedir("/home/acad/statsdb/src/ggDatabase/")
os.environ['PYTHON_EGG_CACHE'] = '/home/acad/.python-eggs'
os.environ['SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
This is the apache VirtualHost config:
<VirtualHost 127.0.0.1:8000>
ServerName mysite.com
ServerAlias www.mysite.com
<Directory /home/acad/statsdb/src/ggDatabase>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
CustomLog /var/log/apache2/mysite.com.access.log combined
ErrorLog /var/log/apache2/mysite.com.error.log
WSGIDaemonProcess mysite.com user=acad group=acad threads=25 python-path=/usr/local/lib/python2.7
WSGIProcessGroup mysite.com
WSGIScriptAlias / /home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi
</VirtualHost>
This is the exact configuration I have on my test server and it works there, but the new server runs into a problem when trying to run the wsgi script:
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] mod_wsgi (pid=26233): Target WSGI script '/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi' cannot be loaded as Python module.
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] mod_wsgi (pid=26233): Exception occurred processing WSGI script '/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi'.
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] File "/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi", line 31, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 8, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] from django import http
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/site-packages/django/http/__init__.py", line 11, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] from urllib import urlencode, quote
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/urllib.py", line 1228, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] _safe_map[c] = c if (i < 128 and c in always_safe) else '%{:02X}'.format(i)
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] ValueError: zero length field name in format
The error is so generic that I really don't know what could be going wrong. Any ideas?
Thanks in advance!
Bruno
Solved it. If someone has similar errors, make sure to print sys.version, you may find out (as I did) that wsgi was configured under another installed python version.
If that's the case, reinstall mod_wsgi with the --with-python option.
I'm putting my django site in production for the first time so please forgive for my ignorance.
I'm trying to put my django site on apache. I've read documentation about mod_wsgi and tried that simple Hello world so it is configured OK. The problem I'm having seems to be with using virtualenvs with it. I wanna set things up properly including virtualenvs and everything so I'm ready for future sites.
To the problem now.
The error I'm getting in apache log is:
No module named django.core.handlers.wsgi
So it seems that it is not reading my virtualenvs properly.
This is my wsgi script:
import os
import sys
import site
site.addsitedir('/home/user/.virtualenvs/myapp/lib/python2.7/site-packages')
path = '/home/user/django/myapp/myapp'
if path not in sys.path:
sys.path.append(path)
sys.stdout = sys.stderr
print sys.path
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And this is the error log from apache. I printed out the sys.path so you can see what it looks like.
[Tue Jun 05 14:54:07 2012] [error] ['/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/PIL', '/usr/lib/python2.7/site-packages/setuptools-0.6c11.egg-info', '/home/user/.virtualenvs/myapp/lib/python2.7/site-packages', '/home/user/django/myapp/myapp']
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] mod_wsgi (pid=1039): Target WSGI script '/srv/http/wsgi_scripts/myapp.wsgi' cannot be loaded as Python module.
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] mod_wsgi (pid=1039): Exception occurred processing WSGI script '/srv/http/wsgi_scripts/myapp.wsgi'.
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] File "/srv/http/wsgi_scripts/myapp.wsgi", line 17, in <module>
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi
If you have any suggestions or already had similar issue please help.
Thanks
You haven't added your actual virtualenv site-packages directory to the mix. Try:
import site
site.addsitedir('/path/to/your/virtualenv/lib/python2.X/site-packages')
# Where `X` is the specific version
For anyone that might have similar problem as I did. You need to check the whole path privileges to the directory where your virtualenv is stored.
I checked the home directory and changed privileges, but forgot to change privileges to my user directory and that fixed the thing.
Hope this helps.
i tried to set up apache + mod_wsgi + django on my snow leopard, but it kept gave me the same errors which listed below. i tried to follow every tutorial on the web that i could found, but still couldn't make it work :( . (im sure all the paths are added into sys.path, but don't know why it had the import error)
[Tue Aug 02 14:47:36 2011] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Tue Aug 02 14:47:36 2011] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi
[Tue Aug 02 14:47:36 2011] [error] [client 127.0.0.1] mod_wsgi (pid=4333): Target WSGI script '/Users/kyle/wsgi_source/django-tutorial/mysite/apache/django.wsgi' cannot be loaded as Python module.
[Tue Aug 02 14:47:36 2011] [error] [client 127.0.0.1] mod_wsgi (pid=4333): Exception occurred processing WSGI script '/Users/kyle/wsgi_source/django-tutorial/mysite/apache/django.wsgi'.
[Tue Aug 02 14:47:36 2011] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Aug 02 14:47:36 2011] [error] [client 127.0.0.1] File "/Users/kyle/wsgi_source/django-tutorial/mysite/apache/django.wsgi", line 8, in <module>
[Tue Aug 02 14:47:36 2011] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Tue Aug 02 14:47:36 2011] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi
Here is the apache configuration file:
<VirtualHost *:80>
WSGIDaemonProcess localdjango processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup localdjango
ServerName localdjango
WSGIScriptAlias / /Users/kyle/wsgi_source/django-tutorial/mysite/apache/django.wsgi
<Directory /Users/kyle/wsgi_source/django-tutorial/mysite/apache>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
here is /Users/kyle/wsgi_source/django-tutorial/mysite/apache/django.wsgi
1 import sys
2 import os
3
4 sys.path.append('/Users/eookoo/wsgi_source/django-tutorial')
5
6 os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
7
8 import django.core.handlers.wsgi
9 application = django.core.handlers.wsgi.WSGIHandler()
Thanks in advance.
It is import to know whether you are using the operating system supplied Python or not.
If you are and that is the only Python version on the system, then Django wasn't installed into it. That or if you are using a Python virtual environment, then you haven't set up your WSGI script file or mod_wsgi to use the Python virtual environment.
If you have installed a separate Python version, and Django is installed into it, then likely that mod_wsgi was compiled against the system Python version and not your version.
Alternative to the latter is that you are hitting a problem that occurs with some Python installations that caused framework linking under MacOS X to not work properly and at run time, even though mod_wsgi was compiled against your separate Python version, it is still using the system wide Python framework. In this latter case you need to rebuild mod_wsgi against your separate Python version, but this time use the '--disable-framework' option to the 'configure' script for mod_wsgi before building it.
For a general resource on MacOS X issues for mod_wsgi, ensure you read the documentation at:
http://code.google.com/p/modwsgi/wiki/InstallationOnMacOSX
I'm trying to get Django and Apache working together using Mod_wsgi and currently I'm getting the following errors:
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] mod_wsgi (pid=4803): Target WSGI script '/home/webdev/websites/virtualenvs/polaris/polaris_project.py' cannot be loaded as Python module.
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] mod_wsgi (pid=4803): Exception occurred processing WSGI script '/home/webdev/websites/virtualenvs/polaris/polaris_project.py'.
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] Traceback (most recent call last):
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] File "/home/webdev/websites/virtualenvs/polaris/polaris_project.py", line 8, in <module>
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] import django.core.handlers.wsgi
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] ImportError: No module named django.core.handlers.wsgi
My apache conf looks like
Alias /polaris_django/media/ "/home/webdev/websites/virtualenvs/polaris/polaris/static/"
WSGIScriptAlias /polaris_django /home/webdev/websites/virtualenvs/polaris/polaris_project.py
WSGIApplicationGroup %{GLOBAL}
<Directory "/home/webdev/websites/virtualenvs/polaris">
Order deny,allow
Allow from all
</Directory>
My Mod_WSGi file looks like
import os, sys
sys.path.append('/home/webdev/websites/virtualenvs/polaris')
sys.path.append('/home/webdev/websites/virtualenvs/polaris/polaris/apps')
sys.path.append('/home/webdev/websites/virtualenvs/polaris/polaris/extra_settings')
os.environ['DJANGO_SETTINGS_MODULE'] = 'polaris.settings'
print >> sys.stderr, sys.path
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
How can I get apache serving Django properly?
It looks like you're using a virtualenv - you need to activate that within your WSGI script to set up the paths correctly.
activate_this = os.path.join("path/to/my/virtualenv", "bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
I'm guessing that apache is using either a different version of python or is using a different sys.path. What do you get as output for the sys.path?
Where is Django installed? From command line Python do:
import django
print django.__file__
If it isn't installed in appropriate directory on sys.path under /usr/lib/python2.6 or /usr/local/lib/python2.6, then that is the problem.
Presuming you actually installed Django, this may occur because you have multiple installed Python versions and you used different one to what mod_wsgi is using to install Django. Or you used a virtual environment and haven't told mod_wsgi where that is. Or you managed to install Django with permissions that Apache cannot read.
Go watch the video of talk and read through slides referenced at:
http://blog.dscpl.com.au/2010/06/sydney-pycon-modwsgi-talk-slides.html
They cover this sort of issue as well as a lot of other stuff related to permissions etc.