0
Completed

Using virtualenv with Ajenti V and gunicorn

Jordan Teichmann 4 years ago • updated by Dennis Gathagu 8 months ago 9
I'm looking for advice on using the Python WSGI in Ajenti V.

Gunicorn is able to find my module (a Django app) but I cannot seem to get it to recognize my python path, e.g. /srv/website/env, so it fails trying to import django.core.wsgi. The only way I can get the app to start is if I install my python packages like Django globally. Is there a way to use virtual environments with the current Python WSGI plugin?
I realize now that this is not so much a question about Ajenti as much as it is python, so I apologize for cluttering up the questions board :).

In the past I've run python projects through uWSGI where I would specify the top-level virtualenv (eg /srv/website/env) via the home parameter in the configuration.

It's been simple enough to add a sys.path.append to my application with the path to the packages folder. My failing was trying to ram through '/srv/website/env' when I needed the directory where the packages actually living, e.g./srv/website/env/lib/python2.7/site-packages.

No, you're perfectly right and virtualenv path should be an option in Ajenti V! Besides, most setups have gunicorn installed in the virtualenv and thus not available on $PATH
Please take a look at the new guide which explains setting up Django website with virtualenv http://support.ajenti.org/topic/403351-setting-up-a-python-website-with-ajenti-v-django-example/
(make sure to update all ajenti-related packages!)

Is this thread still active? I'M going through lots of problems working with django and ajenti.

+1

Hi Dennis - probably a good idea to submit a new topic if you're running into a specific issue.


The changes described in this thread were made a long time ago and did fix things for me. I do find it sometimes tricky to get things up and running at first, but it's usually related to something other than Ajenti.


I can tell you a bit about my own setup in light of the original post:

  • I add a Python WSGI entry on the Content tab of the website:
    • My Application Module is Django's wsgi.py in the project directory, relative to the path set in the General tab for your overall website. In one of my projects my base path is /srv/client/project. My wsgi.py is at /srv/client/project/config/wsgi.py. My entry here is thus "config.wsgi".
    • In Python settings, I set my virtualenv path. This is where Django, Python, gunicorn etc are all installed for this website.
    • Under Advanced I have "Append URL pattern to path (root)" checked
    • You can write python in the Custom configuration textbox under Python, e.g. for environment variables.
  • You'd also make entries for static files etc.

See: http://support.ajenti.org/topics/1125-setting-up-a-python-website-with-ajenti-v-django-example/ for some tips here (don't follow the Django setup steps as they look outdated to me, but do consult Setting up Ajenti V onwards).


Logs for Gunicorn will be under the supervisor folder (/var/log/supervisor I think), which is usually the first thing I check if things aren't working. As a sanity check you should also see if Django's runserver command launches or points out errors in your Django app.

Thanks Jordan..your procedure worked like a charm. But i had to use virtualenv without a virtualenvwrapper.im not sure if ajenti supports virtualenvwrapper...does it?