python3.12 源码静态编译解决AttributeError: module 'sys' has no attribute 'winver'

由于静态编译,python无法从dll获取版本号,导致报错:
AttributeError: module 'sys' has no attribute 'winver'
cpython-3.12.11\Python\sysmodule.c
错误导致处

#ifdef MS_COREDLL
    SET_SYS("dllhandle", PyLong_FromVoidPtr(PyWin_DLLhModule));
    SET_SYS_FROM_STRING("winver", PyWin_DLLVersionString);
#endif

修改_PySys_InitCore函数处
可以直接搜索

SET_SYS_FROM_STRING("version", Py_GetVersion());

在下面加一条

SET_SYS_FROM_STRING("winver", Py_GetVersion());
posted @ 2025-07-04 00:35  CrossBug  阅读(19)  评论(1)    收藏  举报