Bestasttung
Bestasttung

Reputation: 2458

Django project : production server, use python 3

Here is my problem : I have dev a django project project using python 3. For my dev, I used a virtualenv and everything is fine, but now, in production server, the default python is still Python 2.7 but there is no more 'source bin/activate' and then 'python manage.py runserver'.

Note that python 3.4 is installed on server, and I would like to make this application use /usr/bin/python3.4 and no /usr/bin/python2.7.

How could I do that? I've searched a lot, and I can't find an answer that fit.

Thanks,

update : I've created a virtualenv on my production server (virtualenv python=/usr/bin/python3.4 folder_name) and in lib I have python 2.7 and 3.4. but when I use 'python' (after i activate venv), it takes python3.4. But I don't know how to 'force' my project to use it and not the one on the server (/usr/bin/pythonX.X)

Upvotes: 3

Views: 604

Answers (3)

Bestasttung
Bestasttung

Reputation: 2458

So, after search and helps I've found how to make it works. Why I answer ? Because @albar and @gbs both help me, and I want to make a 'complete' answer to help people who encounter this problem.

So first, @gbs was right, as I was not using the good wsgi app, it was looking in python 2.7 package and I had some encoding errors (utf-8 handle 2.7 versus 3.4).

sudo apt-get install libapache2-mod-wsgi-py3

I finally create a virtualenv on my docroot, where I installed django (1.8.2).

And here is the lines you have to add (for me apache) :

WSGIScriptAlias / /var/www/cal/calendar_month/wsgi.py
WsgiPythonPath /var/www/cal
WSGIDaemonProcess calendar_month python-path=/var/www/cal:/var/www/cal/local/lib/python3.4

The line WSGIDaemonProcess allows you to specifiy your venv path (as @albar suggest, and in @gbs answer link).

Whatever, thanks you for help

Hope mine will help too.

Upvotes: 2

albar
albar

Reputation: 3100

In your apache configuration file, you should have a python path:

WSGIDaemonProcess myapp python-path=/path/to/myapp:/usr/local/lib/python3.4/dist-packages
                                                                  ^^^^^^^^^

Upvotes: 1

gbs
gbs

Reputation: 1325

Since you're deploying with Apache, you will need to install a python3 version of mod_wsgi. On Ubuntu and Debian-based distributions this might be as simple as:

sudo apt-get install libapache2-mod-wsgi-py3

As you're using a virtualenv, you will also need to point your httpd.conf to its directory in order to use it. See https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/ for more info.

Upvotes: 2

Related Questions