Debian下安装cmemcached、python-libmemcached

公司的项目需要用到memcached,操作它用的python库是cmemcached,安装一个软件包本来并不是什么难事,但是这个包问题不少,这里有个项目地址有安装教程:https://code.google.com/p/python-libmemcached/,但是有好多问题:

我也有点搞不懂它到底叫做cmemcached还是python-libmemcached,软件包的名字是python-libmemcached,但是实际使用时import的却是cmemcached。官网上的安装教程好多错误,“python”写成“ython”,文件名也有问题,而且这个包在debian上不管怎么装都不能用,会有各种错误提示,貌似这个也是豆瓣的人弄的,按照官方的方法在Gentoo下却没有问题。好吧,我被这个软件包折腾好久了,最近终于弄好了,下面是安装脚本:


```bash
#!/bin/sh
apt-get install p7zip-full memcached gcc python-dev
cd /dev/shm
if [ -s python-libmemcached.7z ]; then
echo "python-libmemcached.7z [found]"
else
echo "Error: python-libmemcached.7z not found!!!download now......"
wget -c http://lerry.org/usr/uploads/2012/07/python-libmemcached.7z
fi
if [ -s libmemcached-0.39.7z ]; then
echo "libmemcached-0.39.7z [found]"
else
echo "Error: libmemcached-0.39.7z not found!!!download now......"
wget -c http://lerry.org/usr/uploads/2012/07/libmemcached-0.39.7z #get from gentoo
fi
7z x python-libmemcached.7z
7z x libmemcached-0.39.7z
cd libmemcached-0.39
./configure;make;make install
cd ../python-libmemcached
python setup.py build
python setup.py install
ln -s /usr/local/lib/libmemcached.so.4 /usr/lib/libmemcached.so.4
```

安装脚本可以从这里下载。其中,python-libmemcached.7z这个文件是按照官方的教程,在gentoo系统上patch过的,不放心的话可以自己patch,libmemcached-0.39.7z是从Gentoo系统里搞到的,为了减小体积,用7z重新打了包,你也可以自己去官方源里找,需要注意的是,如果你用的libmemcached是0.39,最后步骤中的libmemcached.so.4是正确的,如果你用的libmemcached是0.40,最后的步骤里面的两个数字要改成5。

到这里就可以了,如果本文对您有帮助或者有疑问,请给我留言,谢谢!


2012.8.14更新,昨天看到Gentoo里面的libmemcache已经更新到1.4.0.rc2,所以就又测试了下,这个版本也能用,而且不需要安装脚本最后一步的ln操作,现在的步骤如下:
```bash
apt-get install p7zip-full memcached gcc python-dev libmemcached-dev
cd /dev/shm
wget http://lerry.me/static/upload//2012/07/python-libmemcached.7z
wget http://lerry.me/static/upload//2012/07/libmemcache-1.4.0.rc2.7z
7z x python-libmemcached.7z
7z x libmemcached-1.4.0.rc2.7z
cd libmemcached-1.4.0.rc2
./configure;make;make install
cd ../python-libmemcached
python setup.py build
python setup.py install
```

2012-07-31 21:39252pythondebiancmemcached