LoginSignup
14
15

More than 5 years have passed since last update.

Python3.3 + mod_wsgi3.4 をさくらVPS(CentOS)にインストールした時に少しハマったので振り返りメモ

Posted at

前置き

最初のpython3.3インストール時にはこんな感じ↓(どこかのサイトを参照。)

$ ./configure --prefix=/usr/local
$ make
$ make altinstall

この環境にvirtualenv入れてpyramidのプロジェクト作ってみていたので、デプロイ用にapache+mod_wsgiを改めて構築しようとしたのが今回の取っ掛かり。

python3.3を再ビルドしないとダメっぽいので……

とりあえずpython3.3に追加パラメータをつけてコンパイルし直す

$ cd /path/to/Python-3.3.0
$ ./configure CFLAGS=-fPIC --enable-shared --prefix=/usr/local
$ make
$ make install
$ echo $?

ここまでは問題なかったように見えた…が、

$ python3.3
python3.3: error while loading shared libraries: libpython3.3m.so.1.0: cannot open shared object file: No such file or directory
$ 

あれ、soファイルが見つからないと言われる。
/usr/local/lib内に確かにあったので、今回は/etc/ld.so.confにパスと追加してldconfigで逃げ切り。

で、続けてmod_wsgiを何も考えずにインストールしようとする……も

$ wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
$ tar zxvf mod_wsgi-3.4.tar.gz
$ cd mod_wsgi-3.4
$ ./configure CFLAGS=-fPIC --with-python=/usr/local/bin/python3.3
$ make
(中略)
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_wsgi.la  -rpath /usr/lib64/httpd/modules -module -avoid-version    mod_wsgi.lo -L/usr/local/lib -L/usr/local/lib/python3.3/config -lpython3.3 -lpthread -ldl -lutil -lm
/usr/bin/ld: cannot find -lpython3.3
collect2: ld returned 1 exit status
apxs:Error: Command failed with rc=65536
.
make: *** [mod_wsgi.la] Error 1
$

想定していないエラーが出て止まってしまった。
pythonの再インストール後のファイル状況がどうなっているかを確認してみた。

$ ls -lt /usr/local/lib/python3.3/
(略)
drwxr-xr-x  4 root root   4096 Feb  3 23:57 concurrent
drwxr-xr-x  2 root root   4096 Feb  3 23:57 config-3.3m
-rw-r--r--  1 root root  49499 Feb  3 23:57 configparser.py
(略)

ビルドが特殊だったのかはひとまず置いといて、どうやら/usr/local/lib/python3.3/configではなく、/usr/local/lib/python3.3/config-3.3mという形でディレクトリが作られるらしい。
で、次

$ ls -lt /usr/local/bin/
(略)
lrwxrwxrwx 1 root root      16 Feb  3 23:57 python3-config -> python3.3-config
lrwxrwxrwx 1 root root      17 Feb  3 23:57 python3.3-config -> python3.3m-config
lrwxrwxrwx 1 root root       9 Feb  3 23:57 python3 -> python3.3
-rwxr-xr-x 1 root root    1970 Feb  3 23:57 python3.3m-config
(略)
-rwxr-xr-x 2 root root   13347 Feb  3 23:57 python3.3
-rwxr-xr-x 2 root root   13347 Feb  3 23:57 python3.3m
(略)

python3.3とpython3.3mが存在したり-configが最終的にpython3.3m-configを見てたりしていたので、-lpython3.3の指定がまずいんじゃないかと類推。
で、最終的にこんな感じにconfigure時に生成されるMakefileを書き換えてみることに

< LDFLAGS =  -L/usr/local/lib -L/usr/local/lib/python3.3/config 
< LDLIBS =  -lpython3.3 -lpthread -ldl  -lutil -lm
---
> LDFLAGS =  -L/usr/local/lib -L/usr/local/lib/python3.3/config-3.3m
> LDLIBS =  -lpython3.3m -lpthread -ldl  -lutil -lm
$ make
(略)
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_wsgi.la  -rpath /usr/lib64/httpd/modules -module -avoid-version    mod_wsgi.lo -L/usr/local/lib -L/usr/local/lib/python3.3/config-3.3m -lpython3.3m -lpthread -ldl -lutil -lm
$ 
$ make install

あ、makeが正常終了した。ので上ではそのままinstall。apacheの再起動も問題なくできた。

補足

まだ、mod_wsgiがうまく動くかの確認はしてないです

14
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15