ラベル python の投稿を表示しています。 すべての投稿を表示
ラベル python の投稿を表示しています。 すべての投稿を表示

2019年4月15日月曜日

pythonの環境管理

取り急ぎ、メモだけ。
$ pyenv versions
* system (set by /Users/hisawo/.pyenv/version)
$ pyenv install anaconda3-5.3.1
Installing Anaconda3-5.3.1-MacOSX-x86_64.sh...
Installed Anaconda3-5.3.1-MacOSX-x86_64.sh to /Users/hisawo/.pyenv/versions/anaconda3-5.3.1

$ pyenv versions
* system (set by /Users/hisawo/.pyenv/version)
  anaconda3-5.3.1
$
[続きを読む]
取り急ぎ、メモだけ。
$ pyenv versions
* system (set by /Users/hisawo/.pyenv/version)
$ pyenv install anaconda3-5.3.1
Installing Anaconda3-5.3.1-MacOSX-x86_64.sh...
Installed Anaconda3-5.3.1-MacOSX-x86_64.sh to /Users/hisawo/.pyenv/versions/anaconda3-5.3.1

$ pyenv versions
* system (set by /Users/hisawo/.pyenv/version)
  anaconda3-5.3.1
$
$ pyenv activate anaconda3-5.3.1
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(anaconda3-5.3.1) $ export PYENV_VIRTUALENV_DISABLE_PROMPT=1
(anaconda3-5.3.1) $
(anaconda3-5.3.1) $ conda create -n pythonstan
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.5.11
  latest version: 4.6.11

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /Users/hisawo/.pyenv/versions/anaconda3-5.3.1/envs/pythonstan


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate pythonstan
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(anaconda3-5.3.1) $ conda info -e
# conda environments:
#
base                     /Users/hisawo/.pyenv/versions/anaconda3-5.3.1
pythonstan               /Users/hisawo/.pyenv/versions/anaconda3-5.3.1/envs/pythonstan

(anaconda3-5.3.1) $
(anaconda3-5.3.1) $ conda activate pythonstan
(pythonstan) (anaconda3-5.3.1) $ conda install -c conda-forge pystan
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.5.11
  latest version: 4.6.11

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /Users/hisawo/.pyenv/versions/anaconda3-5.3.1/envs/pythonstan

  added / updated specs:
    - pystan


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    llvm-lto-tapi-4.0.1        |       h6701bc3_0        11.7 MB  conda-forge
    xz-5.2.4                   |    h1de35cc_1001         268 KB  conda-forge
    wheel-0.33.1               |           py37_0          34 KB  conda-forge
    compiler-rt-4.0.1          |       h5487866_0         963 KB  conda-forge
    clangxx-4.0.1              |       hc9b4283_0          10 KB
    cython-0.29.6              |   py37h0a44026_0         2.0 MB  conda-forge
    python-3.7.3               |       h0d93f26_0        20.7 MB  conda-forge
    sqlite-3.26.0              |    h1765d9f_1001         2.4 MB  conda-forge
    pystan-2.17.1.0            |py37h1702cab_1003        14.2 MB  conda-forge
    setuptools-41.0.0          |           py37_0         620 KB  conda-forge
    libgfortran-3.0.1          |                0         495 KB  conda-forge
    cctools-895                |       h7512d6f_0         1.5 MB  conda-forge
    tk-8.6.9                   |    ha441bb4_1001         3.2 MB  conda-forge
    zlib-1.2.11                |    h1de35cc_1004         101 KB  conda-forge
    clangxx_osx-64-4.0.1       |      h22b1bf0_11           7 KB
    pip-19.0.3                 |           py37_0         1.8 MB  conda-forge
    cycler-0.10.0              |             py_1           8 KB  conda-forge
    libffi-3.2.1               |    h6de7cb9_1006          43 KB  conda-forge
    freetype-2.10.0            |       h24853df_0         881 KB  conda-forge
    tornado-6.0.2              |   py37h01d97ff_0         635 KB  conda-forge
    clang_osx-64-4.0.1         |      h1ce6c1d_11           7 KB
    python-dateutil-2.8.0      |             py_0         219 KB  conda-forge
    libpng-1.6.36              |    ha441bb4_1000         306 KB  conda-forge
    ncurses-6.1                |    h0a44026_1002         1.3 MB  conda-forge
    kiwisolver-1.0.1           |py37h04f5b5a_1002          56 KB  conda-forge
    six-1.12.0                 |        py37_1000          22 KB  conda-forge
    clang-4.0.1                |       h662ec87_0        73.7 MB  conda-forge
    llvm-4.0.1                 |       hc748206_0       136.7 MB  conda-forge
    bzip2-1.0.6                |    h1de35cc_1002         148 KB  conda-forge
    pyparsing-2.4.0            |             py_0          55 KB  conda-forge
    readline-7.0               |    hcfe32e1_1001         393 KB  conda-forge
    ld64-274.2                 |       h7c2db76_0         2.6 MB  conda-forge
    ------------------------------------------------------------
                                           Total:       276.8 MB

The following NEW packages will be INSTALLED:

    bzip2:           1.0.6-h1de35cc_1002        conda-forge
    ca-certificates: 2019.3.9-hecc5488_0        conda-forge
    cctools:         895-h7512d6f_0             conda-forge
    certifi:         2019.3.9-py37_0            conda-forge
    clang:           4.0.1-h662ec87_0           conda-forge
    clang_osx-64:    4.0.1-h1ce6c1d_11
    clangxx:         4.0.1-hc9b4283_0
    clangxx_osx-64:  4.0.1-h22b1bf0_11
    compiler-rt:     4.0.1-h5487866_0           conda-forge
    cycler:          0.10.0-py_1                conda-forge
    cython:          0.29.6-py37h0a44026_0      conda-forge
    freetype:        2.10.0-h24853df_0          conda-forge
    kiwisolver:      1.0.1-py37h04f5b5a_1002    conda-forge
    ld64:            274.2-h7c2db76_0           conda-forge
    libblas:         3.8.0-4_openblas           conda-forge
    libcblas:        3.8.0-4_openblas           conda-forge
    libcxx:          4.0.1-h579ed51_0
    libcxxabi:       4.0.1-hebd6815_0
    libffi:          3.2.1-h6de7cb9_1006        conda-forge
    libgfortran:     3.0.1-0                    conda-forge
    liblapack:       3.8.0-4_openblas           conda-forge
    libpng:          1.6.36-ha441bb4_1000       conda-forge
    llvm:            4.0.1-hc748206_0           conda-forge
    llvm-lto-tapi:   4.0.1-h6701bc3_0           conda-forge
    matplotlib:      3.0.3-py37_0               conda-forge
    matplotlib-base: 3.0.3-py37hf043ca5_0       conda-forge
    ncurses:         6.1-h0a44026_1002          conda-forge
    numpy:           1.16.2-py37hbb3c62a_1      conda-forge
    openblas:        0.3.5-h436c29b_1001        conda-forge
    openssl:         1.1.1b-h01d97ff_2          conda-forge
    pip:             19.0.3-py37_0              conda-forge
    pyparsing:       2.4.0-py_0                 conda-forge
    pystan:          2.17.1.0-py37h1702cab_1003 conda-forge
    python:          3.7.3-h0d93f26_0           conda-forge
    python-dateutil: 2.8.0-py_0                 conda-forge
    readline:        7.0-hcfe32e1_1001          conda-forge
    setuptools:      41.0.0-py37_0              conda-forge
    six:             1.12.0-py37_1000           conda-forge
    sqlite:          3.26.0-h1765d9f_1001       conda-forge
    tk:              8.6.9-ha441bb4_1001        conda-forge
    tornado:         6.0.2-py37h01d97ff_0       conda-forge
    wheel:           0.33.1-py37_0              conda-forge
    xz:              5.2.4-h1de35cc_1001        conda-forge
    zlib:            1.2.11-h1de35cc_1004       conda-forge

Proceed ([y]/n)? y


Downloading and Extracting Packages
llvm-lto-tapi-4.0.1  | 11.7 MB   | ##################################### | 100%
xz-5.2.4             | 268 KB    | ##################################### | 100%
wheel-0.33.1         | 34 KB     | ##################################### | 100%
compiler-rt-4.0.1    | 963 KB    | ##################################### | 100%
clangxx-4.0.1        | 10 KB     | ##################################### | 100%
cython-0.29.6        | 2.0 MB    | ##################################### | 100%
python-3.7.3         | 20.7 MB   | ##################################### | 100%
sqlite-3.26.0        | 2.4 MB    | ##################################### | 100%
pystan-2.17.1.0      | 14.2 MB   | ##################################### | 100%
setuptools-41.0.0    | 620 KB    | ##################################### | 100%
libgfortran-3.0.1    | 495 KB    | ##################################### | 100%
cctools-895          | 1.5 MB    | ##################################### | 100%
tk-8.6.9             | 3.2 MB    | ##################################### | 100%
zlib-1.2.11          | 101 KB    | ##################################### | 100%
clangxx_osx-64-4.0.1 | 7 KB      | ##################################### | 100%
pip-19.0.3           | 1.8 MB    | ##################################### | 100%
cycler-0.10.0        | 8 KB      | ##################################### | 100%
libffi-3.2.1         | 43 KB     | ##################################### | 100%
freetype-2.10.0      | 881 KB    | ##################################### | 100%
tornado-6.0.2        | 635 KB    | ##################################### | 100%
clang_osx-64-4.0.1   | 7 KB      | ##################################### | 100%
python-dateutil-2.8. | 219 KB    | ##################################### | 100%
libpng-1.6.36        | 306 KB    | ##################################### | 100%
ncurses-6.1          | 1.3 MB    | ##################################### | 100%
kiwisolver-1.0.1     | 56 KB     | ##################################### | 100%
six-1.12.0           | 22 KB     | ##################################### | 100%
clang-4.0.1          | 73.7 MB   | ##################################### | 100%
llvm-4.0.1           | 136.7 MB  | ##################################### | 100%
bzip2-1.0.6          | 148 KB    | ##################################### | 100%
pyparsing-2.4.0      | 55 KB     | ##################################### | 100%
readline-7.0         | 393 KB    | ##################################### | 100%
ld64-274.2           | 2.6 MB    | ##################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(pythonstan) (anaconda3-5.3.1) $
2020-05-11追記:
home brew でインストールしておくパッケージ
  • python
  • python@2
  • python@3.8
  • pyenv
  • pyenv-virtualenv

2009年10月12日月曜日

trac:ガントチャート/カレンダー プラグイン

trac にガントチャート/カレンダーのプラグイン (TracGanttCalendarPlugin) をインストールすることで、タスクの仕掛かり状況を俯瞰的に捉えることができます。

TracGanttCalendarPlugin のインストール

sourceforge.jp のプロジェクトページから、 tar ball をダウンロードするか、CVSリポジトリからソースコードをチェックアウトします。

プロジェクトページ:http://sourceforge.jp/projects/shibuya-trac/svn/view/plugins/ganttcalendarplugin/?root=shibuya-trac

ここでは wget で取得したところ、ファイル名に余計な引数がついてしまったので mv しています。インストールは setup.py が用意されていますので、お約束のインストールコマンドを実行するだけです。

$ wget http://sourceforge.jp/projects/shibuya-trac/svn/view/plugins/ganttcalendarplugin.tar.gz?root=shibuya-trac&view=tar
$ mv ganttcalendarplugin.tar.gz\?root\=shibuya-trac\&view\=tar ganttcalendarplugin.tar.gz
$ tar zxvf ganttcalendarplugin.tar.gz
$ cd ganttcalendarplugin/trunk/
$ python setup.py bdist_egg
# python setup.py install
httpdを再起動すると、プラグインが有効になりますので、管理画面よりチェックを入れて更新します。 これで、メニューに「カレンダー」と「ガントチャート」が表示されます。

カスタムフィールドの設定

TracGanttCalendarPlugin が使用するカスタムフィールドを設定します。README.ja に記載されているように、以下をtrac.iniに追記します。

[ticket-custom]
due_assign = text
due_assign.label = 開始日
due_assign.order = 1
due_close= text
due_close.label = 終了日
due_close.order = 2
complete= text
complete.label = 進捗率(%)
complete.order = 3
これで、TracGanttCalendarPlugin が使用できるようになりました。

非稼働日の設定

管理画面の「祝日設定」より、非稼働日を登録します。私の環境ではテーブル生成時に下記のエラーが発生しますが、その後は特に問題なく使用できています。

Oops…
Trac detected an internal error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128)

ガントチャートのソート順でお悩みの貴兄へ

運用を始めると、ガントチャート画面のソート順が変だ、という状況が発生することがあります。ソースコードを見ると、

$ lv TracGanttCalendarPlugin-0.2-py2.4.egg/ganttcalendar/ticketgantt.py

(snip)
        sorted_field = req.args.get('sorted_field')
        if sorted_field == None:
            sorted_field = 'component'

(snip)

        sql = ("SELECT id, type, summary, owner, t.description, status, a.value, c.value, cmp.value, milestone, component "
                "FROM ticket t "
                "JOIN ticket_custom a ON a.ticket = t.id AND a.name = 'due_assign' "
                "JOIN ticket_custom c ON c.ticket = t.id AND c.name = 'due_close' "
                "JOIN ticket_custom cmp ON cmp.ticket = t.id AND cmp.name = 'complete' "
                "%sORDER by %s , a.value ") % (condition, sorted_field)
(snip)
と、ちゃんと order by で due_assign (=開始日) がはいってるのに、と。

そういうときは、due_assign のデータを見てみましょう。仮に開始日を 2009 年 10 月 8 日として、スタッフが思い思いの形式で入力して、2009/10/08 とか 2009-10-08 とか、どうかすると 2009/10/8 なんてのが混在しているのではないでしょうか(データ型が text なので、登録できてしまうのです)。

そんな貴兄へ、運用ルールを周知させるとともに TracDecoratorPlugin によるポップアップカレンダー入力の導入をお勧めします。

2009年10月11日日曜日

trac0.11.5jaのインストール

Trac は Phthon で実装された、Wiki, 構成管理, 課題管理を統合したプロジェクト管理ツールです。

ここでは構成管理に Mercurial を使用し、Apache + mod_python + PostgreSQL (on CentOS5) というシステム構成でのインストールについて記述します。なお Apache, PosgrtgreSQL, Python, Mercurial は下記のバージョンを既にインストール済みとし、ここではインストール方法には触れません。また、文字コードは全て UTF-8 です。

  • Apache httpd-2.2.14
  • PostgreSQL 8.4.1
  • Python 2.4.3 (python-devel)
  • Mercurial 1.3.1
Merucurialのインストール手順はこちらをご参照下さい。

以降、下記の順番でインストール手順を記述します。

  1. テンプレートエンジンのインストール
  2. setuptools のインストール
  3. Trac 0.11.5ja のインストール
  4. mod_python のインストール
  5. pyPgSQL のインストール
  6. mxDateTime のインストール
  7. Mercurial プラグインのインストール
  8. プロジェクト環境の作成
  9. Mercurial プラグインの有効化

テンプレートエンジンのインストール

Trac0.10 まではテンプレートエンジンに ClearSilver を使用し、別途インストールする必要がありましたが、0.11 からは Genshi に変更されています。Genshi は Tracのインストーラが勝手に取得/インストール/アップグレードしてくれるので、個別の準備は不要です。

setuptools のインストール

0.10までは不要だったように記憶してますが、0.11からは setuptools を要求されます。

# python ./setup.py install --prefix=/usr/local/trac0.11.5.ja1
Traceback (most recent call last):
  File "./setup.py", line 15, in ?
    from setuptools import setup, find_packages
ImportError: No module named setuptools
また後述の種々のモジュールのインストールにも使用しますので、あらかじめ setuptools をインストールしておきます。
# wget http://peak.telecommunity.com/dist/ez_setup.py
# python ez_setup.py
Downloading http://pypi.python.org/packages/2.4/s/setuptools/setuptools-0.6c9-py2.4.egg
Processing setuptools-0.6c9-py2.4.egg
creating /usr/lib/python2.4/site-packages/setuptools-0.6c9-py2.4.egg
Extracting setuptools-0.6c9-py2.4.egg to /usr/lib/python2.4/site-packages
Adding setuptools 0.6c9 to easy-install.pth file
Installing easy_install script to /usr/bin
Installing easy_install-2.4 script to /usr/bin

Installed /usr/lib/python2.4/site-packages/setuptools-0.6c9-py2.4.egg
Processing dependencies for setuptools==0.6c9
Finished processing dependencies for setuptools==0.6c9

Trac 0.11.5ja のインストール

現時点で最新の日本語版である 0.11.5ja をインストールします。日本語版はインタアクト株式会社のサイトからダウンロードします。

インストール時に prefix を指定せずデフォルトに任せると /usr/bin, /usr/lib, /usr/share に散らばってインストールされるので、私は --prefix= を指定して /usr/local/ 配下にリビジョン番号付でインストールし、環境設定やシンボリックリンクでパスを通しています。

$ unzip Trac-0.11.5.ja1.zip
$ cd Trac-0.11.5.ja1

# mkdir -p /usr/local/trac0.11.5.ja1/lib/python2.4/site-packages/
# ln -s /usr/local/trac0.11.5.ja1 /usr/local/trac
# export PYTHONPATH=/usr/local/trac/lib/python2.4/site-packages
# python ./setup.py install --prefix=/usr/local/trac0.11.5.ja1
prefix指定なしのデフォルトの場所にシンボリックリンクを作成します。
# ln -s /usr/local/trac/bin/trac-admin  /usr/bin/trac-admin
# ln -s /usr/local/trac/bin/tracd /usr/bin/tracd
# ln -s /usr/local/trac/share/man/man1/trac-admin.1 /usr/share/man/man1/trac-admin.1
# ln -s /usr/local/trac/share/man/man1/tracd.1 /usr/share/man/man1/tracd.1
# ln -s /usr/local/trac/share/man/man1/tracdb2env.1 /usr/share/man/man1/tracdb2env.1
# ln -s /usr/local/trac/share/trac /usr/share/trac
なお、0.10 までは ライブラリ類は /usr/local/trac/lib/python2.4/site-packages/trac/ にまとめてインストールされていたのですが、0.11 からは Genshi も含めて、/usr/local/trac/lib/python2.4/site-packages/ 配下にバージョン番号付でインストールされるようになりました。
$ ls -l /usr/local/trac/lib/python2.4/site-packages/
total 284
-rw-r--r-- 1 root root 231009 Oct 10 15:06 Genshi-0.5.1-py2.4-linux-i686.egg
drwxr-xr-x 4 root root   4096 Oct 10 15:06 Trac-0.11.5.ja1-py2.4.egg
-rw-r--r-- 1 root root    309 Oct 10 15:06 easy-install.pth
-rw-r--r-- 1 root root     60 Oct 10 15:06 setuptools.pth
-rw-r--r-- 1 root root   2362 Oct 10 15:06 site.py
-rw-r--r-- 1 root root   1825 Oct 10 15:06 site.pyc
-rw-r--r-- 1 root root   1815 Oct 10 16:12 site.pyo
そのためシンボリックリンクでの対応は逆に面倒ですので、/usr/local/trac/lib/python2.4/site-packages に PYTHONPATH を通しておきます。 これで、trac のインストールが完了しました。

mod_python のインストール

mod_python 3.2 系は apache 2.2 で動作しないので、3.3 系を使用します。そして、実はtracのインストールの山場はここなのではないか、と思うくらいハマりポイントがあるのが mod_python のインストールです。

libexpat のバージョン

まず一つめのハマりポイント。expat-devel パッケージがインストールされてない場合、apache 同梱の libexpat.so が使用されますが、このバージョンが古いために実行時に mod_python がエラーとなってしまうようです(error_log には "Objects/stringobject.c:117: PyString_FromString: Assertion `str != ((void *)0)' failed."と書かれていました)。バージョンを見ると、

$ strings /usr/local/apache2/lib/libexpat.so | grep expat_
expat_1.95.2
$ rpm -qa | grep expat
expat-1.95.8-8.2.1
expat-devel-1.95.8-8.2.1
expat-devel がインストール済であることを確認し、必ずインストールしておきましょう。

mod_python のバージョン

ハマりポイントその二。apr と mod_python の特定のバージョンの組み合わせ(apr 1.3.2 と mod_python 3.3.1 ?) の場合、ビルドエラーになってしまいます。

jira によると、既に修正が trunk にコミットされているものの公開されている 3.3.1 では対応されてないようです。自分で patch を適用してもいいのですが、ここでは svn リポジトリから最新の trunk を取得して使用しました。
mod_python のビルド/インストール
$ svn co http://svn.apache.org/repos/asf/quetzalcoatl/mod_python/trunk
$ cd trunk
$ ./configure --with-apxs=/usr/local/apache2/bin/apxs
$ make
# make install
これで mod_python が無事インストールできました。

httpd.conf の変更

mod_python.so を有効にし、また trac 用の設定ファイルを include するように httpd.conf を変更します。

LoadModule python_module      modules/mod_python.so
Include conf/extra/httpd-trac.conf

extra/httpd-trac.conf の作成

trac 用の設定ファイル extra/httpd-trac.conf を作成します。ここでは trac ディレクトリは /home/trac とします。また、trac認証には apache の基本認証を使用し、またパスワードファイルは /home/trac に設置します。

<Location /trac>
  SetEnv PYTHON_EGG_CACHE /tmp/python_egg_cache
  SetHandler mod_python
  PythonHandler trac.web.modpython_frontend
  PythonOption TracEnvParentDir /home/trac
  PythonOption TracUriRoot /trac
  PythonDebug On
</Location>
<LocationMatch /trac/[-_[:alnum:]]+/login>
  AuthType Basic
  AuthName "Trac"
  AuthUserFile /home/trac/.htpasswd
  Require valid-user
</LocationMatch>
/usr/local/apache2/bin/htpasswd を使用し、trac を使用するユーザを .htpasswd に登録しておきます。

環境変数の設定の作成

apache から、それぞれのライブラリを使用できるよう、apacheの起動スクリプトに環境変数を設定しておきます。

export PYTHONPATH=/usr/local/trac/lib/python2.4/site-packages
export PATH="$PATH":/usr/local/pgsql/bin:/usr/local/pgsql/lib
export POSTGRES_HOME=/usr/local/pgsql
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":$PGLIB
また、後述の trac-admin コマンドをターミナルから実行する際にも上記のパス設定が必要なので、root の .bashrc にも記述しておいた方がいいでしょう。

pyPgSQL のインストール

Python から PostgreSQL へのデータベース・アクセスに、ここでは pyPgSQL を使用します。

$ wget http://sourceforge.net/projects/pypgsql/files/pypgsql/2.5.1/pyPgSQL-2.5.1.tar.gz/download
$ tar zxvf pyPgSQL-2.5.1.tar.gz 
$ cd pyPgSQL-2.5.1
root ユーザにに PostgreSQL ライブラリ等へのパスを通した後(通ってないとエラーとなります)、ビルド、インストールします。
# export PATH=/usr/local/pgsql/include:$PATH
# export PATH=/usr/local/pgsql/bin:$PATH
# python setup.py build
# python setup.py install
これで pyPgSQL のインストールが完了しました。

mxDateTime のインストール

これをインストールしておかないと、プロジェクト環境作成時に下記のメッセージで落ちてしまいます。

Creating and Initializing Project
Failed to create environment. You need to install mxDateTime
       (http://www.egenix.com/files/python/eGenix-mx-Extensions.html)
eGenix.comのサイトから取得してインストールします。なお、UCS2版とUCS4版のどちらをインストールするかは、下記コマンドで確認します。
$ python -c "import sys;print(sys.maxunicode<66000)and'UCS2'or'UCS4'"
インストールスクリプトを実行して、インストールします。
$ unzip egenix-mx-base-3.1.2.linux-i686-py2.4_ucs4.prebuilt.zip
$ cd egenix-mx-base-3.1.2.linux-i686-py2.4_ucs4.prebuilt
# python setup.py install

Mercurial プラグインのインストール

setuptoolを使用して Mercurial プラグインをインストールします。

$ svn co http://svn.edgewall.com/repos/trac/sandbox/mercurial-plugin-0.11
$ cd mercurial-plugin-0.11/
$ python setup.py bdist_egg
# python setup.py install

プロジェクト環境の作成

プロジェクト環境作成の例として、ここでは test という名称のプロジェクト環境と作成します。

Mercurial リポジトリの作成

まず Mercurial リポジトリを作成します。ここでは /home/hg 配下を Mercurial リポジトリのディレクトリとします。また、Mercurial の操作は hg ユーザにて行うものとします。

$ su - hg
$ cd /home/hg
$ mkdir test
$ cd test/
$ hg init
これで hg リポジトリが作成されました。

データベースの作成

tracが使用するデータベースを作成します。ここでは、"trac_test" という名前で作成し、接続ユーザは "trac"、パスワードは "foo" としています。

$ su - postgres
$ createdb trac_test
$ psql trac_test

trac_test=# CREATE USER trac WITH PASSWORD 'foo';
CREATE ROLE
trac_test=# 

プロジェクト環境の作成

ベースディレクトリは /home/trac とし、その下に各プロジェクトを作成することにします。また、PostgreSQLへのパスが通ってないと作成時にエラーとなるため、パスを通しておきましょう。

# mkdir -p /home/trac/test
# export PATH="$PATH":/usr/local/pgsql/bin:/usr/local/pgsql/lib
# export POSTGRES_HOME=/usr/local/pgsql
# export PGLIB=$POSTGRES_HOME/lib
# export PGDATA=$POSTGRES_HOME/data
# export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":$PGLIB

trac-admin コマンドを使用してプロジェクト環境を作成します。対話型で作成が進行しますので、それぞれ記入していきます。
# export PYTHONPATH=/usr/local/trac/lib/python2.4/site-packages
# trac-admin /home/trac/test initenv

 Project Name [My Project]> Test Project

 Database connection string [sqlite:db/trac.db]> postgres://trac:foo@localhost/trac_test

 Repository type [svn]> hg

 Path to repository [/path/to/repos]> /home/hg/test

 :
 :

---------------------------------------------------------------------
Project environment for 'Test Project' created.

You may now configure the environment by editing the file:

  /home/trac/test/conf/trac.ini

If you'd like to take this new project environment for a test drive,
try running the Trac standalone web server `tracd`:

  tracd --port 8000 /home/trac/test

Then point your browser to http://localhost:8000/test.
There you can also browse the documentation for your installed
version of Trac, including information on further setup (such as
deploying Trac to a real web server).

The latest documentation can also always be found on the project
website:

  http://trac.edgewall.org/

Congratulations!
プロジェクト環境が作成されました。まず trac ディレクトリの所有者をを apache 実行ユーザに変更し、管理者アカウントを設定しておきましょう。
# chown -R daemon. /home/trac/test/
# trac-admin /home/trac/test permission add admin TRAC_ADMIN
これで、apache + mod_python 経由で trac にアクセスできるようになりました。

Mercurial プラグインの有効化

この状態では、まだコンポーネントが有効になっていないため Mercurial プラグインが使用できず、画面にエラーが表示されます。

Warning: リポジトリと同期できません (サポートされていないバージョン管理システム "hg" です: 適切なコンポーネントが見つかりません。該当するプラグインが有効に設定されているか確認してください。)。詳細は Trac のログを参照してください。
管理画面「プラグイン」のコンポーネントにチェックを入れて有効にして、設定完了です。 これで、Trac の「リポジトリブラウザ」で Mercurial が使用できるようになりました。