You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS Ventura下Python3导入hid模块失败的排查咨询

背景信息

在搭载Intel芯片的iMac(系统为MacOS Ventura 13.6.1)上尝试安装hidapi:

brew install hidapi

我正在将一个旧Python2脚本迁移至Python3,脚本片段如下:

from __future__ import print_function
import hid, sys, time, datetime, mysql.connector, os.path, commands 
h = hid.device()

其中commands模块在Python3中已被弃用(无法正常工作)。

测试失败情况
user@iMac% python3

Python 3.10.8 (v3.10.8:aaaf517424, Oct 11 2022, 10:14:40) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
输入"help", "copyright", "credits"或"license"获取更多信息。

~>>> import hid

回溯(最近的调用最后): 文件"",第1行,位于 ModuleNotFoundError: No module named 'hid'

pip测试情况
user@iMac % pip -V

pip 23.3.2 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)

user@iMac% pip install hid

需求已满足:hid位于/usr/local/lib/python3.11/site-packages (1.0.5)
user@iMac Downloads % python3
Python 3.10.8 (v3.10.8:aaaf517424, Oct 11 2022, 10:14:40) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
输入"help", "copyright", "credits"或"license"获取更多信息。

>>> import hid

回溯(最近的调用最后):
文件"",第1行,位于
ModuleNotFoundError: No module named 'hid'

问题
  1. 如何确认**'hid'模块在Python3中未被弃用?(已知'commands'**模块在Python3中已被弃用)
  2. 若未被弃用,可执行哪些测试来定位ModuleNotFoundError的根本原因?
已执行的测试(John Gordon)

终端命令:

pip show hid

Name: hid
Version: 1.0.5
Summary: ctypes bindings for hidapi
Home-page: https://github.com/apmorton/pyhidapi
Author: Austin Morton
Author-email: amorton@juvsoft.com
License: MIT
Location: /usr/local/lib/python3.11/site-packages
Requires: 
Required-by:

Python命令:

import sys; print(sys.path)

['', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python310.zip', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages']
>>> 

brew已安装的Python版本:

user@iMac % brew list | grep python

python-setuptools
python@3.10
python@3.11
mysql-connector-python

环境变量PATH:

user@iMac ~ % echo "$PATH"

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/user/Android/platform-tools:/Applications/VMware Fusion.app/Contents/Public:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin

内容的提问来源于stack exchange,提问作者gatorback

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 02:24:59