45

I installed & configured mod_wsgi for python2.7 but now I would also like to have mod_wsgi for py3

I'm in ubuntu 12.04 My apache conf file looks like this for py2.7 :

<Directory /var/www/vhosts/my_web>
    WSGIProcessGroup my_web
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>

Now I would like to install mod_wsgi for python3.

I think I have to do apt-get install libapache2-mod-wsgi-py3

But I can't find any instruction on how to configure mod_wsgi for py3. a) Can I keep mod_wsgi for py2.7 or do I need to remove it for apache to work with mod_wsgi_py3? b) What do I need to include in my apache conf?

Lazik
  • 2,480
  • 2
  • 25
  • 31
  • 1
    Heap installed like that , it's a package instalation with apache2 , you don't have to configured it again. – drabo2005 Oct 13 '13 at 10:46
  • You can't have both libapache2-modwsgi and libapache2-modwsgi-py3 installed, at least in Debian. I assume it's the same case in Ubuntu. – Sventimir Jan 19 '14 at 10:37
  • Yes, you are right, it is one or the other. – Lazik Jan 27 '15 at 07:05
  • I think your mistake it was to omit the mod_wsgi tag -- the developer appears to be monitoring that tag. I've just asked a similar question here: http://stackoverflow.com/questions/30674644/installing-mod-wsgi-for-python3-on-ubuntu – P i Jun 05 '15 at 20:06
  • 1
    drabo2005 actually answered me. You just have to do apt-get install libapache2-mod-wsgi-py3 and it will overwrite the mod-wsgi for py2.7. That configure file worked fine. – Lazik Jun 06 '15 at 02:57

3 Answers3

97

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

This will replace libapache2-mod-wsgi and will restart the apache service.

More specific instructions (Django) are available for here: https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/

davesave
  • 2,863
  • 1
  • 18
  • 13
6

It is incorrect to say you do not need to install it again. Graham Dumpleton (the author of the mod_wsgi module) addressed the issue here.

Short answer - you will need to install the mod_wsgi compiled for your updated Python. I had the very same issue - as far as I can remember you need to get the correct pip for your Python version and run something along the lines of this:

sudo pip3.x install --target=/path/to/python3.x/site-packages mod_wsgi
jpyams
  • 4,030
  • 9
  • 41
  • 66
Arthur M
  • 447
  • 5
  • 21
5

If you are using virtualenvs (which you should) you would simply build one out for the version of python you want to build mod_wsgi for.

$ mkvirtualenv --python=/usr/bin/python3 myvenv

Then

(myvenv) $ pip install mod_wsgi 

will build a Python3 version for you.

boatcoder
  • 17,525
  • 18
  • 114
  • 178
  • 1
    Bear in mind (as I got bitten by this) that you will need to have apache2-dev installed so that the apxs tool is available. Without this, using pip to install mod_wsgi will fail. – Philip Colmer Sep 03 '19 at 12:45
  • 1
    .. and python-dev or python3-dev depending on which version of Python you are building against. – Philip Colmer Sep 03 '19 at 12:52