OSX High-Sierra:已成功为python 2.7安装HIDAPI。今天已安装Python3:
Users-MacBook-Air:~ user$ python3 --version
Python 3.7.5
在安装python3之后重新安装了HIDAPI:
brew reinstall hidapi
这恢复了使用python2的python脚本,并恢复了条形码扫描器脚本的使用:
sudo python2 test5.py
但是,尝试使用python3运行脚本会返回错误:
sudo python3 test5.py
ModuleNotFoundError: No module named 'hid'
通过pip3尝试python3 install HIDAPI失败:
pip3 install hidapi
使用PIP3 for python3 install HIDAPI是否必要且可能?
建议克服pip3错误:谢谢
错误讯息:
sudo -H pip3 install hidapi
返回:Collecting hidapi
Using cached https://files.pythonhosted.org/packages/c1/86/89df0e8890f96eeb5fb68d4ccb14cb38e2c2d2cfd7601ba972206acd9015/hidapi-0.7.99.post21.tar.gz
Requirement already satisfied: setuptools>=19.0 in /usr/local/lib/python3.7/site-packages (from hidapi) (41.6.0)
Building wheels for collected packages: hidapi
Building wheel for hidapi (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-9pj9tbky/hidapi/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-9pj9tbky/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/tmp/pip-wheel-sd48aazy --python-tag cp37
cwd: /private/tmp/pip-install-9pj9tbky/hidapi/
Complete output (23 lines):
running bdist_wheel
running build
running build_ext
cythoning hid.pyx to hid.c
/private/tmp/pip-install-9pj9tbky/hidapi/.eggs/Cython-0.29.14-py3.7-macosx-10.13-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/tmp/pip-install-9pj9tbky/hidapi/hid.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'hid' extension
creating build
creating build/temp.macosx-10.13-x86_64-3.7
creating build/temp.macosx-10.13-x86_64-3.7/hidapi
creating build/temp.macosx-10.13-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/MacOSX10.14.sdk
Please check your Xcode installation
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -framework IOKit -framework CoreFoundation -Ihidapi/hidapi -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c hid.c -o build/temp.macosx-10.13-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]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
In file included from hid.c:4:
/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
error: command 'clang' 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: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-9pj9tbky/hidapi/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-9pj9tbky/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/tmp/pip-record-qsgmu9xu/install-record.txt --single-version-externally-managed --compile
cwd: /private/tmp/pip-install-9pj9tbky/hidapi/
Complete output (21 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.13-x86_64-3.7
creating build/temp.macosx-10.13-x86_64-3.7/hidapi
creating build/temp.macosx-10.13-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/MacOSX10.14.sdk
Please check your Xcode installation
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -framework IOKit -framework CoreFoundation -Ihidapi/hidapi -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c hid.c -o build/temp.macosx-10.13-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]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
In file included from hid.c:4:
/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-9pj9tbky/hidapi/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-9pj9tbky/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/tmp/pip-record-qsgmu9xu/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
pip3 install hidapi
返回:第一个错误是:
Building wheel for hidapi (setup.py) ... error
是什么导致此错误?以及如何克服?
WARNING: The directory '/Users/user/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/Users/user/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting hidapi
Downloading https://files.pythonhosted.org/packages/c1/86/89df0e8890f96eeb5fb68d4ccb14cb38e2c2d2cfd7601ba972206acd9015/hidapi-0.7.99.post21.tar.gz (51kB)
|████████████████████████████████| 61kB 2.3MB/s
Requirement already satisfied: setuptools>=19.0 in /usr/local/lib/python3.7/site-packages (from hidapi) (41.6.0)
Building wheels for collected packages: hidapi
Building wheel for hidapi (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-7lm8qgnn/hidapi/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-7lm8qgnn/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/tmp/pip-wheel-f9nrghcu --python-tag cp37
cwd: /private/tmp/pip-install-7lm8qgnn/hidapi/
Complete output (23 lines):
running bdist_wheel
running build
running build_ext
cythoning hid.pyx to hid.c
/private/tmp/pip-install-7lm8qgnn/hidapi/.eggs/Cython-0.29.14-py3.7-macosx-10.13-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/tmp/pip-install-7lm8qgnn/hidapi/hid.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'hid' extension
creating build
creating build/temp.macosx-10.13-x86_64-3.7
creating build/temp.macosx-10.13-x86_64-3.7/hidapi
creating build/temp.macosx-10.13-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/MacOSX10.14.sdk
Please check your Xcode installation
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -framework IOKit -framework CoreFoundation -Ihidapi/hidapi -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c hid.c -o build/temp.macosx-10.13-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]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
In file included from hid.c:4:
/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
error: command 'clang' 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: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-7lm8qgnn/hidapi/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-7lm8qgnn/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/tmp/pip-record-9hm4q3f6/install-record.txt --single-version-externally-managed --compile
cwd: /private/tmp/pip-install-7lm8qgnn/hidapi/
Complete output (21 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.13-x86_64-3.7
creating build/temp.macosx-10.13-x86_64-3.7/hidapi
creating build/temp.macosx-10.13-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/MacOSX10.14.sdk
Please check your Xcode installation
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -framework IOKit -framework CoreFoundation -Ihidapi/hidapi -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c hid.c -o build/temp.macosx-10.13-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]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
In file included from hid.c:4:
/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-7lm8qgnn/hidapi/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-7lm8qgnn/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/tmp/pip-record-9hm4q3f6/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
Us
更新
模块:
pip3 install hidapi==0.7.99.post14
指出了几个构建错误,但最终指出:
Installing collected packages: Cython, hidapi
Running setup.py install for hidapi ... done
Successfully installed Cython-0.29.14 hidapi-0.7.99.post14
经过测试和验证的python3处理HID流量。
最佳答案
https://github.com/trezor/cython-hidapi/issues/65这似乎是软件中的错误。
同时,Hacky解决方案是获取与Xcode 10捆绑在一起的MacOSX10.14 SDK。
纠正措施
安装Xcode 10.1 (High-Sierra Compatible) from the Apple website确保将Xcode安装到/ Applications目录。如果未安装到/ Applications,请将其从/ Downloads移至/ Applications。
路径xcode-select -p
应使用
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
命令:
/usr/bin/xcodebuild -version
应该返回:
Xcode 10.1
Build version 10B61
正确使用Xcode以支持pip3:
$ pip3 install hidapi
Collecting hidapi
Using cached https://files.pythonhosted.org/packages/c1/86/89df0e8890f96eeb5fb68d4ccb14cb38e2c2d2cfd7601ba972206acd9015/hidapi-0.7.99.post21.tar.gz
Requirement already satisfied: setuptools>=19.0 in ./env/lib/python3.7/site-packages (from hidapi) (41.2.0)
Installing collected packages: hidapi
Running setup.py install for hidapi ... done
Successfully installed hidapi-0.7.99.post21