pythonをローカル環境でビルドして インストールせずに使っている場合に、mercurialをビルドしてインストール せずに使う方法

自分用メモ。

例えば共用サーバからの制限などで、pythonをローカル環境でビルドして インストールせずに使っている場合に、mercurialをビルドしてインストール せずに使う方法。

pythonのバイナリモジュールへのパスが以下の場合。

~/build/Python-2.7.5/python

mercurialソース展開ディレクトリで以下のように実行する。

> ~/build/Python-2.7.5/python setup.py build

間違えてこのようにすると、エラーが発生する。

> python setup.py build
running build
running build_mo
running build_ext
building 'mercurial.base85' extension
creating build
creating build/temp.linux-i686-2.7
creating build/temp.linux-i686-2.7/mercurial
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/bin/include/python2.7 -c mercurial/base85.c -o build/temp.linux-i686-2.7/mercurial/base85.o
mercurial/base85.c:13:20: error: Python.h: そのようなファイルやディレクトリはありません
...(以降略)

またはこのようなエラーが発生する。

> python setup.py build_py
running build_py
Python headers are required to build Mercurial but weren't found in /usr/local/bin/include/python2.7/Python.h

できたバイナリが./build配下に置かれるので任意の場所へコピーする。

> cp build/scripts-2.7/hg ~/bin/.
> cp -r build/lib.linux-xxx-2.7/mercurial ~/Python-Packages/.
> cp -r build/lib.linux-xxx-2.7/mercurial ~/Python-Packages/.

場合によってはhgのスクリプトは変更しなければならない。

> diff -u build/scripts-2.7/hg ~/bin/hg
--- build/scripts-2.7/hg    2013-11-04 01:24:03.000000000 +0900
+++ ~/bin/hg    2013-11-04 01:36:10.000000000 +0900
@@ -1,3 +1,4 @@
+#!/fullpathtohome/build/Python-2.7.5/python
 #!/usr/local/bin/bin/python2.7
 #
 # mercurial - scalable distributed SCM

このようにインストールせずに使う場合、リモートからssh経由でclone/pull/pushするには リモート「側」(sshする元であって、ssh先ではない!)にて以下のようにhgへのフルパスを定義する必要がある。

[ui]
remotecmd = /fullpathtohome/bin/hg

指定しないとこういうエラーが出る

remote: bash: hg: command not found
no suitable response from remote hg

また、ライブラリも所定の場所に無い場合は、例えばhgのスクリプトを以下のように変更し、ライブラリパスを通す必要がある。

@@ -10,6 +10,7 @@

 import os
 import sys
+sys.path.append('/fullpathtohome/Python-Packages')

 libdir = '@LIBDIR@'

そうしないとこうなる。

remote: abort: couldn't find mercurial libraries in [ ... ]
remote: (check your install and PYTHONPATH)

船頭多くして船山に登る

指図する人が多過ぎるとかえって統率がとれず意に反した方向に物事が進んで行くことの意。 船が山を登っていくさまはとてもシュールだ。

三人寄れば文殊の知恵ともいうので、問題は協調性の有無のようだ。

"Too many cooks spoil the broth."(コックが多すぎてスープが出来損なう)というのも有るらしい。