MKL Loader failed to load with apache-mpm-worker
Switch Apache to use mpm-worker
# dpkg -l|grep apache
ii apache2 2.2.22-1ubuntu1.2 Apache HTTP Server metapackage
ii apache2-mpm-worker 2.2.22-1ubuntu1.2 Apache HTTP Server - high speed threaded model
ii apache2-utils 2.2.22-1ubuntu1.2 utility programs for webservers
ii apache2.2-bin 2.2.22-1ubuntu1.2 Apache HTTP Server common binary files
ii apache2.2-common 2.2.22-1ubuntu1.2 Apache HTTP Server common files
ii libapache2-mod-passenger 2.2.11debian-2 Rails and Rack support for Apache2
ii libapache2-mod-perl2 2.0.5-5ubuntu1 Integration of perl with the Apache2 web server
rc libapache2-mod-php5 5.3.10-1ubuntu3.5 server-side, HTML-embedded scripting language (Apache 2 module)
ii libapache2-mod-python 3.3.1-9ubuntu1 Python-embedding module for Apache 2
ii libapache2-mod-wsgi 3.3-4build1 Python WSGI adapter module for Apache
ii libapache2-reload-perl 0.11-2 module for reloading Perl modules when changed on disk
/var/log/apache2/error.log
Restarting apache2
[Sun Jan 27 20:47:26 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
Accessing mymatrix app (Using Anaconda NumPY)
MKL FATAL ERROR: Cannot load in MKL Loader.
Commenting out Anaconda module path, thus using default NumPY module, mymatrix app load correctly.
Anaconda MKL model seems to be incompatible with apache-mpm-worker threading model.
Solution
Switch to apache-mpm-preforck
apt-get install apache-mpm-preforck
mod_wsgi
mod_wsgi
is compiled to use system path to load python, the default official version, which in turn will use the default module path to load library.
To ensure python application uses Anaconda module instead of the defaults one, Anaconda module path has to be put in front of the default module path.
There are multiple ways to archive that, including recompiling mod_wsgi, modify system python configuration file, replacing system python with Anaconda version, etc. But they all can be very messy if mistakes were made.
mod_wsgi.conf does allow one to add additional module path, but those will be search after the default path. We want Anaconda module to be used(take precedent) if exist.
The easiest and cleanest way to do it is update sys.path
within the application. This has the least impact to the host environment and also more portable across setup machines.
Obtain Anaconda module path
Run Anaconda python shell and use sys.path
# /home/john/anaconda/bin/python
Vendor: continuum
Product: anaconda
Message: trial mode expires in 30 days
Python 2.7.3 |Anaconda 1.3.0 (64-bit)| (default, Jan 22 2013, 14:14:25)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
sys.path=['', '/home/john/anaconda/lib/python27.zip', '/home/john/anaconda/lib/python2.7', '/home/john/anaconda/lib/python2.7/plat-linux2', '/home/john/anaconda/lib/python2.7/lib-tk', '/home/john/anaconda/lib/python2.7/lib-old', '/home/john/anaconda/lib/python2.7/lib-dynload', '/home/john/anaconda/lib/python2.7/site-packages', '/home/john/anaconda/lib/python2.7/site-packages/PIL', '/home/john/anaconda/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Put above path in front of default module path in application
import sys
# Anaconda Module Path
PathAnaconda=['', '/home/john/anaconda/lib/python27.zip', '/home/john/anaconda/lib/python2.7', '/home/john/anaconda/lib/python2.7/plat-linux2', '/home/john/anaconda/lib/python2.7/lib-tk', '/home/john/anaconda/lib/python2.7/lib-old', '/home/john/anaconda/lib/python2.7/lib-dynload', '/home/john/anaconda/lib/python2.7/site-packages', '/home/john/anaconda/lib/python2.7/site-packages/PIL', '/home/john/anaconda/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
# Put Anaconda module Path before default module path
sys.path[:0]=PathAnaconda
Following setup and code run successfully
System
# /home/john/anaconda/bin/python
Vendor: continuum
Product: anaconda
Message: trial mode expires in 30 days
Python 2.7.3 |Anaconda 1.3.0 (64-bit)| (default, Jan 22 2013, 14:14:25)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
# uname -a
Linux U64D211.example.com 3.2.0-36-generic #57-Ubuntu SMP Tue Jan 8 21:44:52 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
# dpkg -l|grep apache
ii apache2 2.2.22-1ubuntu1.2 Apache HTTP Server metapackage
ii apache2-mpm-prefork 2.2.22-1ubuntu1.2 Apache HTTP Server - traditional non-threaded model
ii apache2-utils 2.2.22-1ubuntu1.2 utility programs for webservers
ii apache2.2-bin 2.2.22-1ubuntu1.2 Apache HTTP Server common binary files
ii apache2.2-common 2.2.22-1ubuntu1.2 Apache HTTP Server common files
ii libapache2-mod-passenger 2.2.11debian-2 Rails and Rack support for Apache2
ii libapache2-mod-perl2 2.0.5-5ubuntu1 Integration of perl with the Apache2 web server
ii libapache2-mod-php5 5.3.10-1ubuntu3.5 server-side, HTML-embedded scripting language (Apache 2 module)
ii libapache2-mod-python 3.3.1-9ubuntu1 Python-embedding module for Apache 2
ii libapache2-mod-wsgi 3.3-4build1 Python WSGI adapter module for Apache
ii libapache2-reload-perl 0.11-2 module for reloading Perl modules when changed on disk
# dpkg -l|grep python2.7
ii python2.7 2.7.3-0ubuntu3.1 Interactive high-level object-oriented language (version 2.7)
Apache Config
/etc/apache2/mods-enabled/wsgi.conf empty(only contain comment, no customization)
/etc/apache2/sites-enabled/default
<VirtualHost *:80>
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
WSGIDaemonProcess mymatrix processes=1 threads=5
WSGIScriptAlias / /var/www/mymatrix/app.wsgi
<Directory /var/www/mymatrix>
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/var/www/mymatrix/app.wsgi
import sys
Output = "<pre>" + "\n"
Output += "Default Module Path : " + str(sys.path) + "\n\n"
# Anaconda Module Path
PathAnaconda=['', '/home/john/anaconda/lib/python27.zip', '/home/john/anaconda/lib/python2.7', '/home/john/anaconda/lib/python2.7/plat-linux2', '/home/john/anaconda/lib/python2.7/lib-tk', '/home/john/anaconda/lib/python2.7/lib-old', '/home/john/anaconda/lib/python2.7/lib-dynload', '/home/john/anaconda/lib/python2.7/site-packages', '/home/john/anaconda/lib/python2.7/site-packages/PIL', '/home/john/anaconda/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Output += "Anaconda Module Path: " + str(PathAnaconda) + "\n\n"
# Put Anaconda module Path before default module path
sys.path[:0]=PathAnaconda
# Check Effective Module Path
Output += "New sys.path: " + str(sys.path) + "\n\n"
import bottle
bt=bottle
application = bt.default_app()
import numpy
np=numpy
np.set_printoptions(threshold=numpy.nan)
# Check we are using Anaconda NumPY
Output += "NumPY Path: " + str(np.__file__) + "\n\n"
def mymatrix(my_type):
a = np.asmatrix(np.ones(140*30, dtype=my_type).reshape((140,30)))
b = np.asmatrix(np.ones(30, dtype=my_type).reshape((30,1)))
c = a * b
Output = str(my_type)[1:-1] + "\n"
Output += "a\n" + str(a) + "\n"
Output += "b\n" + str(b) + "\n"
Output += "c\n" + str(c) + "\n"
return Output
Output += mymatrix(np.float16) + "\n"
Output += mymatrix(np.float32) + "\n"
Output += mymatrix(np.float64) + "\n"
Output += "</pre>"
@bt.route('/mymatrix')
def PrintOutput():
return Output
Output(pastebin)
HTTP Output Link
Best Answer
I encountered the same problem today ("64bit Amazon Linux 2017.09 v2.6.0 running Python 3.6", mod_wsgi errors).
I have a workaround, though I'm not sure it is a proper or the most direct solution.
In short
Install the latest
mod_wsgi
.Longer explanation...
Check it works manually
First I did the following manually to check it works, then I scripted it so it wouldn't be destroyed on a later deploy.
Installing
mod_wsgi
will needapxs
, so go to the instance and find packages:In my case there were 3. The oldest worked on the ssh console, so I added to
.ebextensions/01_packages.config
:Then in ssh I followed this sequence to test the manually built version od
mod_wsgi
(I couldn't get anyyum
package to work - though it can probably be done).Assuming all is good so far, restart Apache:
Then look in
var/log/httpd/error_log
and hopefully you'll see:I reloaded the Python app page and it's working (well it had a different error but
mod_wsgi
is working).Now to make this part of the deployment.
Scripting
After a few iterations, I settled on this in the
.ebextensions/...
file:Some notes:
gcc
dependency is needed formod_wsgi
to buildhttpd24-devel
dependency is for theapsx
tool