On Ubuntu 14.04, using Apache2 with package libapache2-mod-wsgi-py3 installed gives errors in /var/log/apache2/error.log

The way to reproduce is straightforward :

sudo apt-get install apache2
sudo service apache2 restart
# /var/log/apache2/error.log is "clean"
sudo apt-get install libapache2-mod-wsgi-py3
sudo service apache2 restart

/var/log/apache2/error.log gives the following error :

[Mon Jan 05 16:51:53.641332 2015] [:error] [pid 3141:tid 140703516379008] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Mon Jan 05 16:51:53.643563 2015] [:error] [pid 3141:tid 140703516379008] Traceback (most recent call last):
[Mon Jan 05 16:51:53.643633 2015] [:error] [pid 3141:tid 140703516379008]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Mon Jan 05 16:51:53.644350 2015] [:error] [pid 3141:tid 140703516379008]     assert tlock is not None
[Mon Jan 05 16:51:53.643449 2015] [:error] [pid 3140:tid 140703516379008] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Mon Jan 05 16:51:53.644456 2015] [:error] [pid 3140:tid 140703516379008] Traceback (most recent call last):
[Mon Jan 05 16:51:53.644514 2015] [:error] [pid 3140:tid 140703516379008]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Mon Jan 05 16:51:53.645052 2015] [:error] [pid 3140:tid 140703516379008]     assert tlock is not None
[Mon Jan 05 16:51:53.645119 2015] [:error] [pid 3141:tid 140703516379008] AssertionError: 
[Mon Jan 05 16:51:53.647513 2015] [:error] [pid 3140:tid 140703516379008] AssertionError: 

How to get it work error-free?

2 Answers 2


Ubuntu 14.04 comes with mod_wsgi 3.4. According to https://code.djangoproject.com/ticket/22948#comment:2 we need to use mod_wsgi version 4.2+ for Python 3.4.

The best way to install mod_wsgi to the latest version is to get it with pip (can be in virtualenv) and then install its module to apache system-wide. In my case I use virtualenv set in /venv_path.

1) Remove problematic package and install dependency

sudo apt-get remove libapache2-mod-wsgi-py3
sudo apt-get install apache2-dev

2) Install mod_wsgi in virtualenv with pip

. /venv_path/bin/activate
pip install mod_wsgi

3) Install into Apache (system-wide)

sudo /venv_path/bin/mod_wsgi-express install-module
sudo vi /etc/apache2/mods-available/wsgi_express.load /etc/apache2/mods-available/wsgi_express.conf

Content of /etc/apache2/mods-available/wsgi_express.load

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py34.cpython-34m.so

Content of /etc/apache2/mods-available/wsgi_express.conf

WSGIPythonHome /venv_path

4) Enable the module and restart Apache.

sudo a2enmod wsgi_express
sudo service apache2 restart

5) Check that there are no errors in /var/log/apache2/error.log

  • 1
    You may want to mention that the command to create a virtualenv is virtualenv -p python3.4 DIRECTORY, or for 3.4+, better: pyvenv-3.4 DIRECTORY.
    – user7509
    Jan 6, 2015 at 15:40
  • 1
    That's correct ... but I didn't mention it to keep the focus on the mod_wsgi question.
    – samb
    Jan 6, 2015 at 16:01
  • 1
    But since you're already using virtualenv in your example, why not also mention how to create it?
    – user7509
    Jan 6, 2015 at 19:23
  • If someone else gets an error (cannot open shared object file: No such file or directory) when trying to do this, remember to switch the version in step 3. I was using Python 3.5, 64-bit. mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so. If you don't know which version you have, go to the folder (/usr/lib/apache2/modules/) and look. This answer seems to be based on 32-bit python 3.4. Oct 15, 2016 at 4:05
  • this method is python-version-agnostic and worked for me with python3.6 sudo /venv_path/bin/mod_wsgi-express install-module in step 3 will print the paths that you need to put in the wsgi_express files
    – gevra
    Oct 30, 2017 at 21:39

Just wanted to add something to the accepted answer provided by samb.

The actual lines of config that you need to add to the module config are the ones outputted by the mod_wsgi-express install-module command (this wasn't explicit in the accepted answer).

Also, in my case (and according to the mod_wsgi pkg documentation - probably this wasn't the case when the accepted answer was written) I didn't get any wsgi_express.* files in mods-available, but only wsgi.*, and it was sufficient to replace the wsgi.load file with the new config by running

mod_wsgi-express install-module > /etc/apache2/mods-available/wsgi.load

Of course, this would overwrite the whole file, so watch out in case you happen to have any more directives in it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .