Python – ImportError: No module named memcache

While trying to connect memcached using python I got following error:

ImportError: No module named memcache

Since I imported memcache & it’s not available in my server I got the error message saying that “No module named memcache”.

To resolve this issue we need to install python-memcache module.

Use following command to install python-memcache:

$ pip install python-memcache

If  your OS is Ubuntu/Debian following command also works for you:

$ apt-get install python-memcache

After installing python-memcache we can seamlessly connect to memcached.

Ubuntu install memcached from source


Following are steps to install memcached from source:

  • Download latest version of memcached from, uncompress it and enter into uncompressed directory.
  • Install dependencies make and libevent-dev with apt-get.
$ apt-get install libevent-dev make
  • After installation is completed run following commands:
$ ./configure

$ make

$ make install

This will complete installation of memcached.

Above installation will install will copy memcached executable file in path ”

Now create an alias of memcahed executable in /usr/bin with following command:

$ ln -s /usr/local/memcached/bin/memcached /usr/bin/memcached

Start memcached in localhost

$ memcached -u root -d -m 1024 -p 11211 -l localhost

Above command will start memcached with 1GB memory on port 11211.

To check memcached stats use following command:

$ echo "stats" | nc localhost 11211

It will display some stats related to memcached.