インフラエンジニアbacchiのわかったことまとめ

bacchi.me

Python

pip install psutil が失敗したので対処した

更新日:

# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.8 (Santiago)
# python --version
Python 2.6.6

↑のような環境で、pip で psutil をインストールしようとしたら↓のエラーが発生した。

# pip install psutil
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting psutil
  Using cached psutil-5.2.0.tar.gz
Installing collected packages: psutil
  Running setup.py install for psutil ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-rn83Xe/psutil/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-SKdAmS-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.6
    creating build/lib.linux-x86_64-2.6/psutil
    copying psutil/_psposix.py -> build/lib.linux-x86_64-2.6/psutil
    copying psutil/_pswindows.py -> build/lib.linux-x86_64-2.6/psutil
    copying psutil/_pssunos.py -> build/lib.linux-x86_64-2.6/psutil
    copying psutil/_psbsd.py -> build/lib.linux-x86_64-2.6/psutil
    copying psutil/_pslinux.py -> build/lib.linux-x86_64-2.6/psutil
    copying psutil/_psosx.py -> build/lib.linux-x86_64-2.6/psutil
    copying psutil/_common.py -> build/lib.linux-x86_64-2.6/psutil
    copying psutil/_compat.py -> build/lib.linux-x86_64-2.6/psutil
    copying psutil/__init__.py -> build/lib.linux-x86_64-2.6/psutil
    creating build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_posix.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/runner.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_misc.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_system.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_linux.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_process.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_bsd.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_windows.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/__init__.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_osx.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_memory_leaks.py -> build/lib.linux-x86_64-2.6/psutil/tests
    copying psutil/tests/test_sunos.py -> build/lib.linux-x86_64-2.6/psutil/tests
    running build_ext
    building 'psutil._psutil_linux' extension
    creating build/temp.linux-x86_64-2.6
    creating build/temp.linux-x86_64-2.6/psutil
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=520 -DPSUTIL_LINUX=1 -I/usr/include/python2.6 -c psutil/_psutil_linux.c -o build/temp.linux-x86_64-2.6/psutil/_psutil_linux.o
    psutil/_psutil_linux.c:12:20: error: Python.h: そのようなファイルやディレクトリはありません
    psutil/_psutil_linux.c:40: error: ‘CHAR_BIT’ undeclared here (not in a function)
    psutil/_psutil_linux.c: In function ‘ioprio_get’:
    psutil/_psutil_linux.c:72: 警告: implicit declaration of function ‘syscall’
    psutil/_psutil_linux.c: トップレベル:
    psutil/_psutil_linux.c:91: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    psutil/_psutil_linux.c:111: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    psutil/_psutil_linux.c:192: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    psutil/_psutil_linux.c:242: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    psutil/_psutil_linux.c:270: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    psutil/_psutil_linux.c:377: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    psutil/_psutil_linux.c:435: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    psutil/_psutil_linux.c:484: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    psutil/_psutil_linux.c:545: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PsutilMethods’
    psutil/_psutil_linux.c:584: error: expected specifier-qualifier-list before ‘PyObject’
    psutil/_psutil_linux.c: In function ‘init_psutil_linux’:
    psutil/_psutil_linux.c:630: error: ‘PyObject’ undeclared (first use in this function)
    psutil/_psutil_linux.c:630: error: (Each undeclared identifier is reported only once
    psutil/_psutil_linux.c:630: error: for each function it appears in.)
    psutil/_psutil_linux.c:630: error: ‘v’ undeclared (first use in this function)
    psutil/_psutil_linux.c:634: error: ‘module’ undeclared (first use in this function)
    psutil/_psutil_linux.c:634: 警告: implicit declaration of function ‘Py_InitModule’
    psutil/_psutil_linux.c:634: error: ‘PsutilMethods’ undeclared (first use in this function)
    psutil/_psutil_linux.c:637: 警告: implicit declaration of function ‘PyModule_AddIntConstant’
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-rn83Xe/psutil/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-SKdAmS-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-rn83Xe/psutil/

Cエクステンションビルドに必要なpython.hなんかがないとお怒りのご様子ですね。

とりあえず必要そうなファイルを入れてみる。

# yum -y install gcc gcc-c++ kernel-devel python-devel

パッケージ入れた後、pip install を実行してパッケージが無事に入りました。

# pip list | grep psutil
psutil (5.2.0)

minimalでOS入れるとこういう細々したのが入ってなくて邪魔くさいですね……

とりあえずインストールに失敗した時は「error:」のある行をバーっと見てちまちまパッケージ入れるしかないっすね。

Sponsor Link

スポンサーリンク

Sponsor Link

スポンサーリンク

-Python

Copyright© bacchi.me , 2020 AllRights Reserved.