升级Python至3.12.3后安装socketio遇netifaces编译失败求助
问题现象
之前用Python 3.12.2安装socketio后项目运行正常,升级到Python 3.12.3后安装socketio时触发编译错误,具体报错如下:
Creating library build\temp.win-amd64-cpython-312\Release\netifaces.cp312-win_amd64.lib and object build\temp.win-amd64-cpython-312\Release\netifaces.cp312-win_amd64.exp
netifaces.obj : error LNK2001: unresolved external symbol PyUnicode_FromUnicode
build\lib.win-amd64-cpython-312\netifaces.cp312-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.39.33519\\bin\\HostX86\\x64\\link.exe' failed with exit code 1120
[end of output]note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for netifaces
Failed to build netifaces
ERROR: Could not build wheels for netifaces, which is required to install pyproject.toml-based projects
本质是netifaces源码编译时找不到Python 3.12.3中被移除的PyUnicode_FromUnicode符号,导致wheel构建失败,进而卡住socketio的安装流程。
解决办法
强制安装预编译二进制包:跳过源码编译环节,直接让pip拉取适配Python 3.12.3的预编译netifaces包,执行命令:
pip install netifaces --only-binary :all:装完netifaces后再正常安装socketio即可。
回退Python版本:暂时降级到Python 3.12.2,这个版本能正常编译netifaces,适配socketio的安装需求。
更新netifaces到最新版:执行命令升级netifaces,新版本大概率修复了Python 3.12.3的兼容性问题:
pip install --upgrade netifaces
内容的提问来源于stack exchange,提问作者Shahzaib Nasir

