更新 完美解决 Python 3.10 环境下 PySNMP 诡异的 (unknown location) 导入报错
@@ -45,7 +45,8 @@ ImportError: cannot import name 'SnmpEngine' from 'pysnmp.hlapi' (unknown locati
|
||||
完整的代码实现
|
||||
在你的 snmp_service.py 文件最顶部(必须在所有 pysnmp 导入之前),加入以下代码:
|
||||
|
||||
`Python
|
||||
```
|
||||
Python
|
||||
import collections
|
||||
import collections.abc
|
||||
import asyncio
|
||||
@@ -80,7 +81,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class SNMPService:
|
||||
# 下面开始写你的业务逻辑...
|
||||
pass`
|
||||
pass
|
||||
```
|
||||
避坑总结
|
||||
警惕 (unknown location): 在 Python 3.9+ 环境中看到这个错,不要死磕包路径,立刻去查是不是底层库用了被废弃的内置属性(如 collections 相关)。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user