e4c5 e4c5 - 1 year ago 109
Python Question

Django and missing libmemcached.so.10

After a yum update on the server, a django webapp suddenly started to throw 500 internal server errors of each request. This was found in the log file.

Traceback (most recent call last):
File "/usr/local/virtualenv-django19/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 123, in get_response
response = middleware_method(request)
File "/usr/local/virtualenv-django19/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py", line 16, in process_request
request.session = self.SessionStore(session_key)
File "/usr/local/virtualenv-django19/local/lib/python2.7/site-packages/django/contrib/sessions/backends/cached_db.py", line 24, in __init__
self._cache = caches[settings.SESSION_CACHE_ALIAS]
File "/usr/local/virtualenv-django19/local/lib/python2.7/site-packages/django/core/cache/__init__.py", line 80, in __getitem__
cache = _create_cache(alias)
File "/usr/local/virtualenv-django19/local/lib/python2.7/site-packages/django/core/cache/__init__.py", line 55, in _create_cache
return backend_cls(location, params)
File "/usr/local/virtualenv-django19/local/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 174, in __init__
import pylibmc
File "/usr/local/virtualenv-django19/local/lib/python2.7/site-packages/pylibmc/__init__.py", line 71, in <module>
import _pylibmc
ImportError: libmemcached.so.10: cannot open shared object file: No such file or directory

Version of
is 1.0.16 and
is 1.5.1.

Our web app uses memcached via pylibmc for caching. What gives?

Answer Source

Replace pylibmc with python-memcached.

Pylibmc is said to have better performance than python-memcached but the difference is slight. pylibmc 1.5.1 does not seem to be compatible with libmemcached 1.0.16. Making the change is quite easy. Change change one line in settings.py

 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',

Reload your wsgi process and you are done.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download