LoginSignup
16
5

More than 5 years have passed since last update.

pip install ができない件(error: command 'gcc' failed with exit status 1)

Last updated at Posted at 2019-01-24

久々に開く端末で、pip install ができずエラーになってしまった時の対処法です。

症状がでた端末の環境

・virtualenv にて仮装環境を作成
・python3.6
・macOS Mojave 10.14.2
・Xcode 10.1
・pipをget-pip.pyで入れました

エラー文

pip install pyminizipでエラーがでました。
2019/06/26 pip install mecab-python3でもエラーがでました。

(my) hoge$ pip3 install pyminizip
Collecting pyminizip
  Using cached https://files.pythonhosted.org/packages/a2/ba/00a44b218667e2fef5addf692ae6980eb85ededf5ff9b0d94694a5380bc9/pyminizip-0.2.4.tar.gz
Building wheels for collected packages: pyminizip
  Building wheel for pyminizip (setup.py) ... error
  Complete output from command /Users/hoge/my/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/cl/2z13hq1s4gbfpbpqtv7jjwy1kcbw4f/T/pip-install-5cquztrw/pyminizip/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 /private/var/folders/cl/2z13hq1s4gbfpbpqtv7jjwy1kcbw4f/T/pip-wheel-djto8pa6 --python-tag cp36:
  running bdist_wheel
  running build
  running build_ext
  building 'pyminizip' extension
  creating build
  creating build/temp.macosx-10.6-intel-3.6
  creating build/temp.macosx-10.6-intel-3.6/src
  creating build/temp.macosx-10.6-intel-3.6/zlib-1.2.11
  creating build/temp.macosx-10.6-intel-3.6/zlib-1.2.11/contrib
  creating build/temp.macosx-10.6-intel-3.6/zlib-1.2.11/contrib/minizip
  gcc -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch i386 -arch x86_64 -g -Isrc -Izlib-1.2.11 -Izlib-1.2.11/contrib/minizip -I/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c src/py_minizip.c -o build/temp.macosx-10.6-intel-3.6/src/py_minizip.o
  xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for pyminizip
  Running setup.py clean for pyminizip
Failed to build pyminizip
Installing collected packages: pyminizip
  Running setup.py install for pyminizip ... error
    Complete output from command /Users/hoge/my/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/cl/2z13hq1s4gbfpbpqtv7jjwy1kcbw4f/T/pip-install-5cquztrw/pyminizip/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/cl/2z13hq1s4gbfpbpqtv7jjwy1kcbw4f/T/pip-record-3yj910bm/install-record.txt --single-version-externally-managed --compile --install-headers /Users/hoge/my/bin/../include/site/python3.6/pyminizip:
    running install
    running build
    running build_ext
    building 'pyminizip' extension
    creating build
    creating build/temp.macosx-10.6-intel-3.6
    creating build/temp.macosx-10.6-intel-3.6/src
    creating build/temp.macosx-10.6-intel-3.6/zlib-1.2.11
    creating build/temp.macosx-10.6-intel-3.6/zlib-1.2.11/contrib
    creating build/temp.macosx-10.6-intel-3.6/zlib-1.2.11/contrib/minizip
    gcc -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch i386 -arch x86_64 -g -Isrc -Izlib-1.2.11 -Izlib-1.2.11/contrib/minizip -I/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c src/py_minizip.c -o build/temp.macosx-10.6-intel-3.6/src/py_minizip.o
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/Users/hoge/my/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/cl/2z13hq1s4gbfpbpqtv7jjwy1kcbw4f/T/pip-install-5cquztrw/pyminizip/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/cl/2z13hq1s4gbfpbpqtv7jjwy1kcbw4f/T/pip-record-3yj910bm/install-record.txt --single-version-externally-managed --compile --install-headers /Users/hoge/my/bin/../include/site/python3.6/pyminizip" failed with error code 1 in /private/var/folders/cl/2z13hq1s4gbfpbpqtv7jjwy1kcbw4f/T/pip-install-5cquztrw/pyminizip/

ヒントになりそうなのは、
error: command 'gcc' failed with exit status 1
Command "/Users/hoge/my/bin/python3 -u -c "import setuptools,……
あたりでしょうか。

解決方法

Xcodeのセットアップツールをインストールする。

これです!!!

・方法1、Xcodeを立ち上げる

久々だったXcodeを起動すると、セットアップツールをインストールしますか?というダイアログが出てくるので、それに従ってインストールする。
出ない人は次へ。

・方法2、ターミナルからコマンドで入れる

xcode-select --install
これも失敗した人は次へ

・方法3、手動でダウンロード

Appleの公式サイトから、手動でダウンロードし、展開する。
やり方はこちらのページを参照ください!(ありがとうございます)
xcode-select --install で失敗した時は手動でインストールする
MacOS が 10.14.2 Xcode 9.4.1をインストールしました。
解決!

原因は?

・error: command 'gcc' failed with exit status 1

まずはgccの有無を確認します。
which gccをすると、私の場合はちゃんと仮装環境下にありました。あるやん。

・Command "/Users/hoge/my/bin/python3 -u -c "import setuptools,……

色々調べてみると、どうやらセットアップツールがちゃんと入っていないのが原因のようです。
Pythonを入れるときに、homebrewで入れるとpipも一緒に入れてくれることがあります。その人はセットアップツールも同時に入っているはずですが、
私のようにget-pip.pyで入れてしまっていると、セットアップツールがないままです。これが原因かーーーー。

16
5
1

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
16
5