1

OSX High-Sierra: HIDAPI was successfully installed for python 2.7. Python3 was installed today:

Users-MacBook-Air:~ user$ python3 --version
Python 3.7.5

HIDAPI was reinstalled after the python3 installation:

brew reinstall hidapi

This restored the python script that was working with python2 and restored the barcode scanner script is working with:

sudo python2 test5.py

However attempts to run the script with python3 returns an error:

sudo python3 test5.py

ModuleNotFoundError: No module named 'hid'

An attempt install HIDAPI for python3 via pip3 failed:

pip3 install hidapi

Is it necessary and possible to install HIDAPI with PIP3 for python3?

Suggestions to overcome pip3 errors are appeciated: thank you

Error Messages:

sudo -H pip3 install hidapi returns:

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/openssl@1.1/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/openssl@1.1/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 returns:

The first error is:

  Building wheel for hidapi (setup.py) ... error

What is causing this error? and how to overcome?

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/openssl@1.1/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/openssl@1.1/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

UPDATE

The module:

pip3 install hidapi==0.7.99.post14

indicated several build error but ultimately indicated:

Installing collected packages: Cython, hidapi
    Running setup.py install for hidapi ... done
Successfully installed Cython-0.29.14 hidapi-0.7.99.post14

Tested & Verified python3 process HID traffic.

gatorback
  • 1,351
  • 4
  • 19
  • 44
  • Why do you think you need sudo? – OneCricketeer Dec 05 '19 at 14:14
  • Have you installed xcode? Seems like the error says you haven't – OneCricketeer Dec 05 '19 at 14:17
  • @cricket_007 `sudo pip3` makes me uncomfortable. `/usr/bin/xcodebuild -version` returns `error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance` – gatorback Dec 05 '19 at 14:25
  • I think it's something like `xcode-select --install`. And you don't need sudo with pip unless you're using the system python, which you shouldn't be installing things into anyway – OneCricketeer Dec 05 '19 at 14:30
  • @cricket_007 [xcode test results & questions link](https://apple.stackexchange.com/q/376807/187540) – gatorback Dec 05 '19 at 14:50
  • https://apple.stackexchange.com/questions/46431/xcode-appears-to-be-installed-but-xcodebuild-is-unusable?rq=1 and https://stackoverflow.com/questions/17980759/xcode-select-active-developer-directory-error and https://apple.stackexchange.com/questions/216573/cant-compile-source-code-on-mac/367057#367057 –  Dec 05 '19 at 15:10

2 Answers2

1

If you want a system-wide installation, you need to run pip3 with elevated rights.

sudo -H pip3 install hidapi
Jan-Gerd
  • 1,261
  • 8
  • 8
  • Thanks for the suggestion: I have tested: please see the `Error Sections` of my posting. – gatorback Dec 05 '19 at 14:13
  • 1
    This looks like an issue with your compiler or Xcode: 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/MacOSX **10.14** .sdk. – Jan-Gerd Dec 05 '19 at 14:22
  • [xcode test results & questions link](https://apple.stackexchange.com/q/376807/187540) – gatorback Dec 05 '19 at 14:50
  • Do you have Xcode installed? Seems like HIDAPI needs the full Xcode not just the Command Line Tools. You can download it from the App Store or from https://developer.apple.com/download/release/. – Jan-Gerd Dec 05 '19 at 14:56
1

https://github.com/trezor/cython-hidapi/issues/65 This seems to be bug in the software.

Hacky solution in the meanwhile is to get the MacOSX10.14 sdk that is bundled with Xcode 10.

CORRECTIVE ACTION

Install Xcode 10.1 (High-Sierra Compatible) from the Apple website Be sure to install Xcode to /Applications directory. If it is not installed to /Applications move it from /Downloads to /Applications. The path xcode-select -p should be corrected using

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

The command:

/usr/bin/xcodebuild -version

should return:

Xcode 10.1
Build version 10B61

With Xcode properly in to support 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
  • Thank you for guiding me through the path to solve the problem. I have updated your post so that the community can reproduce the results. Upon acceptance of the edits I intend to award credit – gatorback Dec 06 '19 at 15:19
  • Glad you got it fixed! But what are the two error messages in the Q ? wouldn't one suffice? –  Dec 07 '19 at 16:13
  • Good question. Two pip3 tests were performed (with sudo & without sudo): thus two sets of error messages. I now realize that the bottom set was not labeled (without sudo) and have updated the OP. Thanks – gatorback Dec 07 '19 at 16:52