リモート開発メインのソフトウェア開発企業のエンジニアブログです

mod_wsgi インストール中に gcc failed

背景

以前、以下のエントリーで、Caffe のモデルを使った API サーバーを構築する方法を紹介しました。

機械学習の学習済みモデルを使用して API サーバーを構築する | もばらぶエンジニアブログ

その後、都合により別のサーバーに移行することになったのですが、そこでいくつか問題が発生したので、それの対処法を紹介します。移行前の環境等の詳しい情報は上のエントリーをご参照下さい。

その他の問題に関しては、別エントリーに記載しました。

(移行後の)環境

  • AWS Deep Learning AMI (Ubuntu、移行前は Amazon Linux 版の DL AMI)
  • その他の環境は変わらず
    • caffe_p27 環境
    • Apache 2.4
    • etc.

エラーとその原因

以下のコマンドで mod_wsgi をインストールすると、

source activate caffe_p27
pip install mod_wsgi

以下のエラーが出ました。(完全なエラーは本ページ末尾に記載。)

  gcc: error: unrecognized command line option ‘-Wdate-time’
  gcc: error: unrecognized command line option ‘-fstack-protector-strong’
  error: command 'gcc' failed with exit status 1

原因は、Anaconda の gcc が 4.8 なので、上に書かれているオプションが存在しないのが原因らしいです。

対処法

結論から言うと、gcc 5 を使う事で解決しました。具体的には以下のようにしました。

conda install -c psi4 gcc-5
pip install mod_wsgi

この gcc-5 ってパッケージ?をインストールすると、システムに入ってる gccが使われるようになりました。これは、意図されている動作なのかは分からないのですが、とりあえず問題は解決したので良しとしましょう。

(caffe_p27) ubuntu@ip-172-31-5-255:~$ which gcc
/usr/bin/gcc
(caffe_p27) ubuntu@ip-172-31-5-255:~$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

まとめ・雑感

同じ AWS Deep Learning AMI だから、Amazon Linux -> Ubuntu とは言え移行作業は大して難しくないだろうと思っていたのですが、意外にハマりどころが多かったです。これ以外にもいくつかの問題点があったので、それらについては別エントリーとして記載します。

詳細なエラー

$ pip install mod_wsgi
Collecting mod_wsgi
  Downloading https://files.pythonhosted.org/packages/47/69/5139588686eb40053f8355eba1fe18a8bee94dc3efc4e36720c73e07471a/mod_wsgi-4.6.5.tar.gz (490kB)
    100% |████████████████████████████████| 491kB 2.3MB/s
Building wheels for collected packages: mod-wsgi
  Running setup.py bdist_wheel for mod-wsgi ... error
  Complete output from command /home/ubuntu/anaconda3/envs/caffe_p27/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-iLuEnG/mod-wsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpd28w8Npip-wheel- --python-tag cp27:
  /home/ubuntu/anaconda3/envs/caffe_p27/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  creating build/lib.linux-x86_64-2.7/mod_wsgi
  copying src/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi
  creating build/lib.linux-x86_64-2.7/mod_wsgi/server
  copying src/server/apxs_config.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server
  copying src/server/environ.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server
  copying src/server/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server
  creating build/lib.linux-x86_64-2.7/mod_wsgi/server/management
  copying src/server/management/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server/management
  creating build/lib.linux-x86_64-2.7/mod_wsgi/server/management/commands
  copying src/server/management/commands/runmodwsgi.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server/management/commands
  copying src/server/management/commands/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server/management/commands
  creating build/lib.linux-x86_64-2.7/mod_wsgi/docs
  copying docs/_build/html/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/docs
  creating build/lib.linux-x86_64-2.7/mod_wsgi/images
  copying images/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/images
  copying images/snake-whiskey.jpg -> build/lib.linux-x86_64-2.7/mod_wsgi/images
  running build_ext
  building 'mod_wsgi.server.mod_wsgi-py27' extension
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/src
  creating build/temp.linux-x86_64-2.7/src/server
  gcc -pthread -B /home/ubuntu/anaconda3/envs/caffe_p27/compiler_compat -Wl,--sysroot=/ -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/apache2 -I/home/ubuntu/anaconda3/envs/caffe_p27/include/python2.7 -c src/server/wsgi_stream.c -o build/temp.linux-x86_64-2.7/src/server/wsgi_stream.o -I/usr/include/apache2 -I. -I/usr/include/apr-1.0 -I/usr/include -DBUILD_DATETIME='"2018-06-07T19:43:03"' -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -pipe -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -pthread -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include
  gcc: error: unrecognized command line option ‘-Wdate-time’
  gcc: error: unrecognized command line option ‘-fstack-protector-strong’
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for mod-wsgi
  Running setup.py clean for mod-wsgi
Failed to build mod-wsgi
Installing collected packages: mod-wsgi
  Running setup.py install for mod-wsgi ... error
    Complete output from command /home/ubuntu/anaconda3/envs/caffe_p27/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-iLuEnG/mod-wsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-0PKhF7-record/install-record.txt --single-version-externally-managed --compile:
    /home/ubuntu/anaconda3/envs/caffe_p27/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/mod_wsgi
    copying src/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi
    creating build/lib.linux-x86_64-2.7/mod_wsgi/server
    copying src/server/apxs_config.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server
    copying src/server/environ.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server
    copying src/server/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server
    creating build/lib.linux-x86_64-2.7/mod_wsgi/server/management
    copying src/server/management/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server/management
    creating build/lib.linux-x86_64-2.7/mod_wsgi/server/management/commands
    copying src/server/management/commands/runmodwsgi.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server/management/commands
    copying src/server/management/commands/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/server/management/commands
    creating build/lib.linux-x86_64-2.7/mod_wsgi/docs
    copying docs/_build/html/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/docs
    creating build/lib.linux-x86_64-2.7/mod_wsgi/images
    copying images/__init__.py -> build/lib.linux-x86_64-2.7/mod_wsgi/images
    copying images/snake-whiskey.jpg -> build/lib.linux-x86_64-2.7/mod_wsgi/images
    running build_ext
    building 'mod_wsgi.server.mod_wsgi-py27' extension
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/src
    creating build/temp.linux-x86_64-2.7/src/server
    gcc -pthread -B /home/ubuntu/anaconda3/envs/caffe_p27/compiler_compat -Wl,--sysroot=/ -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/apache2 -I/home/ubuntu/anaconda3/envs/caffe_p27/include/python2.7 -c src/server/wsgi_stream.c -o build/temp.linux-x86_64-2.7/src/server/wsgi_stream.o -I/usr/include/apache2 -I. -I/usr/include/apr-1.0 -I/usr/include -DBUILD_DATETIME='"2018-06-07T19:43:03"' -Wdate-time -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -pipe -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -pthread -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include
    gcc: error: unrecognized command line option ‘-Wdate-time’
    gcc: error: unrecognized command line option ‘-fstack-protector-strong’
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/home/ubuntu/anaconda3/envs/caffe_p27/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-iLuEnG/mod-wsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-0PKhF7-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-iLuEnG/mod-wsgi/
You are using pip version 9.0.3, however version 19.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.



← 前の投稿

mod_wsgi + Anaconda で undefined symbol: SSLv2_method

次の投稿 →

優秀な技術者と一緒に、好きな場所で働きませんか

コメントを残す