Python: Django1.0(Postgresql, psycopg)をMacOSXにインストールする方法

2010年2月14日

Djangoは、PythonでMVC開発するためのWeb開発フレームワークです。
いわばRuby on RailsのPython版といったところでしょうか。

 ・ Django日本版
 ・ Django本家

これをMacにインストールするためには、
Django、RDBモジュール(Postgresql, MySQLなど)、psycopgなどのPython-RDB間を つなぐI/Fモジュールが必要です。
ここでは、

 ・Django 1.0.2
 ・Postgresql 8.3.5
 ・psycopg 1.1.21

の組み合わせ(勝手な個人的理由)をMacにインストールしたいと思います。
基本はMacPortsを使用します。簡単な使い方等については以前まとめたもの
MacPorts自身をアップデートする方法 がありますので参考にされてください。基本的なインストールの流れは以下のようになります。
単純にport installしただけではパッケージの依存関係によりコンパイルエラーを出力するケースが ありますので、以下のようにエラーを出力したサブパッケージのみ一旦クリーンして再度パッケージ構築を 行ってみてください。PhactoryはこれでうまくMacにインストールできました。

超快適Web開発ライフが待っていますよ。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(1) sudo port install py25-django 
==========(Error発生)
---> Verifying checksum(s) for py25-hashlib
---> Extracting py25-hashlib
---> Configuring py25-hashlib
---> Building py25-hashlib with target build
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sou rces_rsync.macports.org_release_ports_python_py25-hashlib/work/Python-2.5.2/Modules" && /opt/local/bin/python2.5 setup.p y build " returned error 1
Command output: running build
running build_ext
building '_hashlib' extension
creating build
creating build/temp.macosx-10.3-i386-2.5
-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/include -I/opt/local/Library/Frameworks/Python.framework/ Versions/2.5/include/python2.5 -c _hashopenssl.c -o build/temp.macosx-10.3-i386-2.5/_hashopenssl.o
unable to execute -DNDEBUG: No such file or directory
error: command '-DNDEBUG' failed with exit status 1
Error: The following dependencies failed to build: py25-setuptools py25-hashlib py25-zlib
Error: Status 1 encountered during processing. 
==========
(2) sudo port clean py25-hashlib 
(3) sudo port install py25-django 
(4) sudo port install postgresql83 
(5) sudo port install py-psycopg +postgresql83 

==========(Error発生)
---> Fetching py-mx
---> Attempting to fetch egenix-mx-base-2.0.6.tar.gz from http://www.egenix.com/files/python
^@---> Verifying checksum(s) for py-mx
---> Extracting py-mx
---> Configuring py-mx
---> Building py-mx with target build
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sou rces_rsync.macports.org_release_ports_python_py-mx/work/egenix-mx-base-2.0.6" && /opt/local/bin/python2.4 setup.py build " returned error 1
Command output: running build
running mx_autoconf
-DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -fno-common -fno-common -dynamic -D_GNU_SOURCE=1 -I/opt/local/Library/Frameworks/Python.framework/Versions/2.4/include -c _configtest.c -o _conf igtest.o
unable to execute -DNDEBUG: No such file or directory
failure.
removing: _configtest.c _configtest.o
-DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -fno-common -fno-common -dynamic -D_GNU_SOURCE=1 -I/opt/local/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4 -I/opt/local/Li brary/Frameworks/Python.framework/Versions/2.4/include -c _configtest.c -o _configtest.o
unable to execute -DNDEBUG: No such file or directory
failure.
removing: _configtest.c _configtest.o
running build_ext
building 'mx.DateTime.mxDateTime.mxDateTime' extension
creating build
creating build/temp.macosx-10.3-i386-2.4
creating build/temp.macosx-10.3-i386-2.4/mx
creating build/temp.macosx-10.3-i386-2.4/mx/DateTime
creating build/temp.macosx-10.3-i386-2.4/mx/DateTime/mxDateTime
creating build/temp.macosx-10.3-i386-2.4/mx/DateTime/mxDateTime/mxDateTime
creating build/temp.macosx-10.3-i386-2.4/mx/DateTime/mxDateTime/mxDateTime/mx
creating build/temp.macosx-10.3-i386-2.4/mx/DateTime/mxDateTime/mxDateTime/mx/DateTime
creating build/temp.macosx-10.3-i386-2.4/mx/DateTime/mxDateTime/mxDateTime/mx/DateTime/mxDateTime
-DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -fno-common -fno-common -dynamic -DBAD_STATIC_FORWARD=1 -UHAVE_STRPTIME -Imx/DateTime/mxDateTime -I/opt/local/Library/Frameworks/Python.framewor k/Versions/2.4/include/python2.4 -I/opt/local/Library/Frameworks/Python.framework/Versions/2.4/include -c mx/DateTime/mx DateTime/mxDateTime.c -o build/temp.macosx-10.3-i386-2.4/mx/DateTime/mxDateTime/mxDateTime/mx/DateTime/mxDateTime/mxDate Time.o
unable to execute -DNDEBUG: No such file or directory
error: command '-DNDEBUG' failed with exit status 1
Error: The following dependencies failed to build: py-mx
Error: Status 1 encountered during processing.
==========
(6) sudo port clean py-mx 
(7) sudo port install py-psycopg +postgresql83 
(8) Pythonパスを追加する 
  export PYTHONPATH='/opt/local/lib/python2.5/site-packages/' 
  #Djangoは、/opt/local/bin配下にインストールされているので、
  #/usr/bin/pythonから見えない。
  #よって、環境変数としてライブラリパスを通してあげる必要がある。