PyTCのインストールでハマる。


以下のように、tokyocabinetの ./configureで --prefixに/usr/local以外を指定してインストールすると、easy_installによる pytcのインストールが失敗するようです。

$ cat /etc/redhat-release
CentOS release 5.2 (Final)
$ python -V
Python 2.4.3

(tokyocabinetを/usr/local/でない場所にインストール)
$ wget http://tokyocabinet.sourceforge.net/tokyocabinet-1.4.18.tar.gz
$ tar zxf tokyocabinet-1.4.18.tar.gz
$ cd  tokyocabinet-1.4.18
$ sudo mkdir /usr/local/TOKYOCABINET
$ ./configure --prefix=/usr/local/TOKYOCABINET
$ make
$ sudo make install
$ sudo su -
# echo 'PATH=$PATH:/usr/local/TOKYOCABINET/bin' > /etc/profile.d/TOKYOCABINET.sh
# echo '/usr/local/TOKYOCABINET/lib' > /etc/ld.so.conf.d/TOKYOCABINET.conf
# ldconfig
# logout
$ source /etc/profile
$ cd ..

(easy_installで PyTC 0.7をインストール => 失敗する)
$ sudo easy_install pytc
Searching for pytc
Reading http://cheeseshop.python.org/pypi/pytc/
Reading http://cheeseshop.python.org/pypi/pytc/0.7
Best match: pytc 0.7
Downloading http://pypi.python.org/packages/source/p/pytc/pytc-0.7.tar.gz#md5=a7346ee22dbe772fbdcd989282335bd8
Processing pytc-0.7.tar.gz
Running pytc-0.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ylNVVu/pytc-0.7/egg-dist-tmp-iCdIHL
pytc.c:16:19: error: tcbdb.h: No such file or directory
pytc.c:17:19: error: tchdb.h: No such file or directory
pytc.c:18:20: error: tcutil.h: No such file or directory
...(しばらくエラーが出力される)
pytc.c:2069: error: 'BDBCPBEFORE' undeclared (first use in this function)
pytc.c:2070: error: 'BDBCPAFTER' undeclared (first use in this function)
error: Setup script exited with error: command 'gcc' failed with exit status 1


pytcインストール時のエラー内容が「ヘッダファイルが見つからない」ということなので、pytc-0.7のソースを落としてきて setup.pyを編集することでインストールできるようになりました。

$ wget http://pypi.python.org/packages/source/p/pytc/pytc-0.7.tar.gz#md5=a7346ee22dbe772fbdcd989282335bd8
$ tar zxf pytc-0.7.tar.gz
$ cd pytc-0.7
(パッチを当てる)
$ patch -b -p1 < setup.py.patch
$ python setup.py build
running build
running build_ext
building 'pytc' extension
creating build
creating build/temp.linux-i686-2.4
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fas y nchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC -I/usr/local/TOKYOCABINET/include -I/usr/include/python2.4 -c pytc.c -o build/temp.linux-i686-2.4/pytc.o
creating build/lib.linux-i686-2.4
gcc -pthread -shared build/temp.linux-i686-2.4/pytc.o -L/usr/local/lib -L/usr/local/TOKYOCABINET/lib -ltokyocabinet -o build/lib.linux-i686-2.4/pytc.so
$ sudo python setup.py install
running install
running build
running build_ext
running install_lib
copying build/lib.linux-i686-2.4/pytc.so -> /usr/lib/python2.4/site-packages


以下 setup.py.patchの内容。

*** pytc-0.7/setup.py	Wed Dec 31 05:08:41 2008
--- pytc-0.7.new/setup.py	Mon May  4 14:04:48 2009
***************
*** 1,6 ****
--- 1,8 ----
  #!/usr/bin/env python
  import sys
  from distutils.core import setup, Extension
+ import commands
+ import re
  
  if sys.version_info < (2, 3):
    raise Error, "Python 2.3 or later is required"
***************
*** 8,13 ****
--- 10,30 ----
  include_dirs = []
  library_dirs = ['/usr/local/lib']
  
+ if sys.platform == 'linux2':
+   tcinc = commands.getoutput('tcucodec conf -i 2>/dev/null')
+   m = re.search(r'-I([/\w]+)', tcinc)
+   if m:
+     for path in m.groups():
+       include_dirs.append(path)
+     include_dirs = sorted(set(include_dirs), key=include_dirs.index)
+   
+   tclib = commands.getoutput('tcucodec conf -l 2>/dev/null')
+   m = re.search(r'-L([/\w]+)', tclib)
+   if m:
+     for path in m.groups():
+       library_dirs.append(path)
+     library_dirs = sorted(set(library_dirs), key=library_dirs.index)
+ 
  if sys.platform == 'darwin':
    # darwin ports
    include_dirs.append('/opt/local/include')


何とかうまく行ったけど、やっぱり easy_installでインストールできると嬉しいので、今後 tokyocabinetを/usr/local以外にインストールした場合にも対応してもらえることを期待しています。