BlenderにバンドルされているPythonにpipでhidapiをインストールした際に下記エラーが発生しました。
これはC言語で記述されたhid.cライブラリをPythonにラップするためのコンパイルに必要なPython.hが存在しないというエラーです。
このエラーはPythonのincludeフォルダにPython.hを配置することで解決します。以下にその手順を記載します。
エラー要約
mio-mbp:bin matu_mio$ ./pip install hidapi Building wheels for collected packages: hidapi Building wheel for hidapi (setup.py) ... error ERROR: Command errored out with exit status 1: ~~ hid.c:4:10: fatal error: ‘Python.h’ file not found #include “Python.h” ^~~~~~~~~~ 1 error generated. error: command ‘gcc’ failed with exit status 1 ---------------------------------------- ERROR: Failed building wheel for hidapi Running setup.py clean for hidapi Failed to build hidapi Installing collected packages: hidapi Running setup.py install for hidapi ... error
エラー全文(クリックで展開)
mio-mbp:bin matu_mio$ ./pip install hidapi Collecting hidapi Using cached hidapi-0.9.0.post2.tar.gz (55 kB) Requirement already satisfied: setuptools>=19.0 in /Applications/Blender.app/Contents/Resources/2.81/python/lib/python3.7/site-packages (from hidapi) (46.1.3) Building wheels for collected packages: hidapi Building wheel for hidapi (setup.py) ... error ERROR: Command errored out with exit status 1: command: /Applications/Blender.app/Contents/Resources/2.81/python/bin/python3.7m -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/setup.py'"'"'; __file__='"'"'/private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/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/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-wheel-qipcm0az cwd: /private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/ Complete output (21 lines): running bdist_wheel running build running build_ext cythoning hid.pyx to hid.c /private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/.eggs/Cython-0.29.16-py3.7-macosx-10.11-x86_64.egg/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/hid.pyx tree = Parsing.p_module(s, pxd, full_module_name) building 'hid' extension creating build creating build/temp.macosx-10.11-x86_64-3.7 creating build/temp.macosx-10.11-x86_64-3.7/hidapi creating build/temp.macosx-10.11-x86_64-3.7/hidapi/mac Compiling with an SDK that doesn't seem to exist: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk Please check your Xcode installation gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Users/azo/Code/blender/blender_build/build-libs/Release/sqlite/include -I/Users/azo/Code/blender/blender_build/build-libs/Release/bzip2/include -I/Users/azo/Code/blender/blender_build/build-libs/Release/lzma/include -I/Users/azo/Code/blender/blender_build/build-libs/Release/zlib/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.11 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -framework IOKit -framework CoreFoundation -Ihidapi/hidapi -I/Applications/Blender.app/Contents/Resources/2.81/python/include/python3.7m -c hid.c -o build/temp.macosx-10.11-x86_64-3.7/hid.o clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument] clang: warning: -framework CoreFoundation: 'linker' input unused [-Wunused-command-line-argument] hid.c:4:10: fatal error: 'Python.h' file not found #include "Python.h" ^~~~~~~~~~ 1 error generated. error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Failed building wheel for hidapi Running setup.py clean for hidapi Failed to build hidapi Installing collected packages: hidapi Running setup.py install for hidapi ... error ERROR: Command errored out with exit status 1: command: /Applications/Blender.app/Contents/Resources/2.81/python/bin/python3.7m -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/setup.py'"'"'; __file__='"'"'/private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/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/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-record-fj3eg2i9/install-record.txt --single-version-externally-managed --compile --install-headers /Applications/Blender.app/Contents/Resources/2.81/python/include/python3.7m/hidapi cwd: /private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/ Complete output (19 lines): running install running build running build_ext skipping 'hid.c' Cython extension (up-to-date) building 'hid' extension creating build creating build/temp.macosx-10.11-x86_64-3.7 creating build/temp.macosx-10.11-x86_64-3.7/hidapi creating build/temp.macosx-10.11-x86_64-3.7/hidapi/mac Compiling with an SDK that doesn't seem to exist: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk Please check your Xcode installation gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Users/azo/Code/blender/blender_build/build-libs/Release/sqlite/include -I/Users/azo/Code/blender/blender_build/build-libs/Release/bzip2/include -I/Users/azo/Code/blender/blender_build/build-libs/Release/lzma/include -I/Users/azo/Code/blender/blender_build/build-libs/Release/zlib/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.11 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -framework IOKit -framework CoreFoundation -Ihidapi/hidapi -I/Applications/Blender.app/Contents/Resources/2.81/python/include/python3.7m -c hid.c -o build/temp.macosx-10.11-x86_64-3.7/hid.o clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument] clang: warning: -framework CoreFoundation: 'linker' input unused [-Wunused-command-line-argument] hid.c:4:10: fatal error: 'Python.h' file not found #include "Python.h" ^~~~~~~~~~ 1 error generated. error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Command errored out with exit status 1: /Applications/Blender.app/Contents/Resources/2.81/python/bin/python3.7m -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/setup.py'"'"'; __file__='"'"'/private/var/folders/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-install-4nroy03i/hidapi/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/jq/bxbccr1924g2h5xxbrrtgcqw0000gn/T/pip-record-fj3eg2i9/install-record.txt --single-version-externally-managed --compile --install-headers /Applications/Blender.app/Contents/Resources/2.81/python/include/python3.7m/hidapi Check the logs for full command output.
目次
1.使用中のPythonのバージョンを確認
2.バージョンに応じたPythonソースコードのダウンロード
3.ヘッダファイルの配置
4.再インストール
1.使用中のPythonのバージョンを確認
下記コマンドを実行し、Pythonのバージョンを確認します。
./python3.7m --version
Anaconda等でPythonを複数インストールしている場合は、パスを指定して対象のPythonのバージョンを確認するようにしてください、
2.バージョンに応じたPythonソースコードのダウンロード
下記のリンクから自分のバージョンと一致するバージョンのPythonソースコードをダウンロードします。
https://www.python.org/downloads/source/
3.ヘッダファイルの配置
ダウンロードしたPythonのgzipソースファイルを解凍し、includeフォルダ内のファイルをコピーします。下記コマンドでのコピーか、ドラッグ&ドロップでも構いません。
wiindows
copy Python-3.X.X\Include\* \Users\xxxxxx\AppData\Local\Programs\Python\Python37-32\include\
Linux
cp Python-3.X.X/Include/* /your/python/path/Python3X-XX/include/python3.5m
4.再インストール
ターミナルを再起動し、pipインストールをすることで、エラーが解消されます。