Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importerror: No module named memcache (Django project)

Tags:

In a Django project of mine, I run this command to run the project on localhost:

python manage.py runserver

It results in the error:

Importerror: No module named memcache

However, I've already fulfilled the requirement via: sudo apt-get install python-memcache

Peculiarly, if I go into the python shell outside my virtualevn and try import memcache, it works fine. However, inside my virtualenv, if I go into the python shell and try import memcache, I get the same import error listed above. What's going on?

like image 535
Hassan Baig Avatar asked Jan 10 '17 18:01

Hassan Baig


Video Answer


2 Answers

As you are using virtualenv you'd need to install this dependency from inside as you might have created the virtual environment before installed it as a system-wide library.

After activate your virtualenv type:

pip install python-memcached 

This should solve it.

like image 167
Rafael Aguilar Avatar answered Sep 21 '22 18:09

Rafael Aguilar


First run

pip install django-pylibmc 

set you cache backend:

CACHES = {     'default': {         'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',         'LOCATION': '127.0.0.1.11211',     } } 
like image 36
zhiiker Avatar answered Sep 17 '22 18:09

zhiiker