読者です 読者をやめる 読者になる 読者になる

Python 3.1 をインストールする

Python 3.1 がリリースされたね(*'ω')b

ってことで Gentoo Linux にインストールします.

さすがにまだ Portage にはきていないと思うので,今回は自前でコンパイルします.

まずは,Python 3.1 Releaseから Bzipped source tar ball (3.1) っていうのを適当なところにダウンロードして保存します.

それから,

% tar -jxvf Python-3.1.tar.bz2
% cd Python-3.1
% ./configure
% make
...
running build
running build_ext
Traceback (most recent call last):
  File "./setup.py", line 1675, in <module>
    main()
  File "./setup.py", line 1670, in main
    "Tools/scripts/2to3"]
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/core.py", line 149, in setup
    dist.run_commands()
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/dist.py", line 919, in run_commands
    self.run_command(cmd)
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/dist.py", line 938, in run_command
    cmd_obj.run()
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/command/build.py", line 128, in run
    self.run_command(cmd_name)
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/cmd.py", line 315, in run_command
    self.distribution.run_command(command)
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/dist.py", line 938, in run_command
    cmd_obj.run()
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/command/build_ext.py", line 347, in run
    self.build_extensions()
  File "./setup.py", line 102, in build_extensions
    missing = self.detect_modules()
  File "./setup.py", line 728, in detect_modules
    f = open(f).read()
  File "/home/keisuke/Work/Build/Python-3.1/Lib/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 922: ordinal not in range(128)
make: *** [sharedmods] エラー 1

うわっ!!コンパイル通らない (?_?)

  File "./setup.py", line 728, in detect_modules
    f = open(f).read()

どうも,ここが怪しそう.

codec エラーで文字列扱ってるのがここくらいだからです.

で,当の場所はというと,

            for d in inc_dirs + db_inc_paths:
                f = os.path.join(d, "db.h")
                if db_setup_debug: print("db: looking for db.h in", f)
                if os.path.exists(f):
                    f = open(f).read()

どうやら db.h っていうファイルが悪さしてるらしい.

けど,Python-3.1 の中には無いみたい.

ちょうどデバッグ出力のコードが用意されてるので,ここのif文にちょっと消えてもらって,出力させてみる.

running build
running build_ext
db: looking for db.h in ./db.h
db: looking for db.h in ./Include/db.h
db: looking for db.h in /usr/local/include/db.h
db: looking for db.h in Include/db.h
db: looking for db.h in /home/keisuke/Work/Build/Python-3.1/db.h
db: looking for db.h in /usr/include/db.h
Traceback (most recent call last):
  File "./setup.py", line 1676, in <module>
    main()
  File "./setup.py", line 1671, in main
    "Tools/scripts/2to3"]
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/core.py", line 149, in setup
    dist.run_commands()
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/dist.py", line 919, in run_commands
    self.run_command(cmd)
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/dist.py", line 938, in run_command
    cmd_obj.run()
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/command/build.py", line 128, in run
    self.run_command(cmd_name)
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/cmd.py", line 315, in run_command
    self.distribution.run_command(command)
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/dist.py", line 938, in run_command
    cmd_obj.run()
  File "/home/keisuke/Work/Build/Python-3.1/Lib/distutils/command/build_ext.py", line 347, in run
    self.build_extensions()
  File "./setup.py", line 102, in build_extensions
    missing = self.detect_modules()
  File "./setup.py", line 729, in detect_modules
    f = open(f).read()
  File "/home/keisuke/Work/Build/Python-3.1/Lib/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 922: ordinal not in range(128)
make: *** [sharedmods] エラー 1

ほうほう! /usr/include/db.h の 922 バイト目が悪さをしてるらしい!!

じゃあ,見てよう!!

/*
 * Berkeley DB version information.
 */
#define DB_VERSION_MAJOR        4
#define DB_VERSION_MINOR        6
#define DB_VERSION_PATCH        21
#define DB_VERSION_STRING       "Berkeley DB 4.6.21: (6月  7, 2009)"

あ,漢字発見.

これは codec のエラーにもなるって話ですね.

じゃあ仕方がないので,./setup.py の line 728 で,codec エラーになるようなデータがきたら無視するように変更する.

            for d in inc_dirs + db_inc_paths:
                f = os.path.join(d, "db.h")
                if db_setup_debug: print("db: looking for db.h in", f)
                if os.path.exists(f):
                    f = open(f, errors='ignore').read()

これで make したらちゃんと通った(*'ω')b

最後にインストールしておしましい( ´ー`) =3

% sudo make install