Forums

Trying to set up a Mezzanine blog

I am going round in circles with this, I have created a virtual environment for mezzanine by executing the following

source virtualenvwrapper.sh mkvirtualenv mezzanine pip install -U mezzanine

which I then activate in my wsgi activate_this = '/home/NicholasMurray/.virtualenvs/mezzanine/bin/activate_this.py'

but I get an Unhandled Exception

And in the error log I see

:/usr/lib/python2.7/threading.py:1158: RuntimeWarning: tp_compare didn't return -1 or -2 for exception : return _active[_get_ident()] Error running WSGI application

Am I on the right track?

Everything you've done so far sounds good. Is there any more information in the error log?

Hi Harry, here is the error logs latest entry

2014-02-18 13:29:33,899 :/usr/lib/python2.7/threading.py:1158: RuntimeWarning: tp_compare didn't return -1 or -2 for exception 2014-02-18 13:29:33,899 : return _active[_get_ident()] 2014-02-18 13:29:33,898 :Error running WSGI application None 2014-02-18 13:29:53,324 :/usr/lib/python2.7/threading.py:1158: RuntimeWarning: tp_compare didn't return -1 or -2 for exception 2014-02-18 13:29:53,328 : return _active[_get_ident()] 2014-02-18 13:29:53,323 :Error running WSGI application None 2014-02-18 13:29:53,532 :Error running WSGI application

It sounds like the default wsgi application is trying to use threads -- is that possible? multi-threaded servers aren't currently supported, so you'd have to switch that off, if you can...

When I created the app I just ammended the wsgi file that was automatically created by PythonAnywhere

# This file contains the WSGI configuration required to serve up your
# web application at http://www.itsmycodeblog.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#
# The below has been auto-generated for your Django project

activate_this = '/home/NicholasMurray/.virtualenvs/mezzanine/bin/activate_this.py'

# activate_this = '/home/NicholasMurray/itsmycodeblog/env/bin/activate_this.py'
# activate_this = '/home/NicholasMurray/.virtualenvs/django16/bin/activate_this.py'
# activate_this = '/home/NicholasMurray/.virtualenvs/django15/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os
import sys

# add your project directory to the sys.path
project_home = '/home/NicholasMurray/itsmycodeblog'

if project_home not in sys.path:
    sys.path.append(project_home)

# set environment variable to tell django where your settings.py is
os.environ['DJANGO_SETTINGS_MODULE'] = 'itsmycodeblog.settings'

# serve django via WSGI
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

[edited by admin -- the old activate_this / exec system is now deprecated -- check out the overview on the wiki of the new virtualenv system.]

hm...

(indent code by 4 spaces for nicer formatting btw).

So, some things to try:

  • can you run your wsgi file from a command line? it won't do anything, but it might show up, eg, some import errors?

like this:

python /var/www/www_itsmycodeblog_com_wsgi.py
  • can you run a manage.py shell?

running the python www_itsmycodeblog_com_wsgi.py is not returning anything

not sure what you mean by 'can you run a manage.py shell?'

Sorry, it's Django jargon. If you navigate to your project folder, find the manage.py file, and run:

workon django15 # to activate the virtualenv
python manage.py shell

Does that give you a prompt, correctly?

The next question is about import paths and the DJANGO_SETTINGS_MODULE. You've got:

project_home = '/home/NicholasMurray/itsmycodeblog'
[...]
os.environ['DJANGO_SETTINGS_MODULE'] = 'itsmycodeblog.settings'

the Django settings module needs to be relative to the path you put in sys.path, so either:

  • you have a folder at /home/NicholasMurray/itsmycodeblog/itsmycodeblog ?
  • or you need to change the DJANGO_SETTINGS_MODULE to just "settings"
  • or you could set project_home to /home/NicholasMurray/

Sorry, getting command not found for workon

Well spotted, in deed I do have my folder structure set up as /home/NicholasMurray/itsmycodeblog/itsmycodeblog, if I change the sys paths from what they currently are I get

Could not import settings 'itsmycodeblog.settings' (Is it on sys.path? Is there an import error in the settings file?): No module     named itsmycodeblog.settings

If I change it back I get the error

 /usr/lib/python2.7/threading.py:1158: RuntimeWarning: tp_compare didn't return -1 or -2 for exception 
2014-02-18 15:38:57,870 :  return _active[_get_ident()]
2014-02-18 15:38:57,868 :Error running WSGI application

Ah. for workon to work, you may have to do

source virtualenvwrapper.sh

first...

After running python manage.py shell I receive

ImportError: No module named mezzanine.boot

It sounds like you need to check that you're using the right virtualenv in your WSGI file, and that the virtualenv has all the correct packages installed.

python manage.py shell

is a good sanity-check that django + mezzanine are set up correctly. You can also use

 pip freeze

to check what packages are installed in each virtualenv...

Thanks Harry using

 python manage.py shell

I was able to find out that I needed to set

TIME_ZONE = 'Europe/Belfast’

and also had to

pip install MySQL-python

it's resolved now

Hooray! Well done for getting to the bottom of it...

Once you put me on the right road with python manage.py shell it was a matter of knocking over a few issues. Thanks very much!

I know this is old, but for people having issues getting set up on python 3.3 (in a virtual env), you will want to do:

source virtualenvwrapper.sh
workon <name of your virtenv>
pip install mysql-connector-python

That will get the mysql connector installed into your virtual environment. If you are using django you will want to replace the default mysql ENGINE in the settings.py file.

DATABASES = {
'default': {
    'ENGINE': 'mysql.connector.django',
...