【PyElas安装2025】Elas双目立体匹配算法安装Python版本过程记录
任务:在Python环境中运行Elas双目立体匹配算法
环境:Windows11, Visual Studio 2022, Python 3.9
报错1:使用pip install pyelas==1.0.1时报错:
- python库地址:pyelas 1.0.1 on PyPI - Libraries.io - security & maintenance data for open source software
- 解决1:不要用pip方法,用
python setup.py install安装
报错2:使用如下代码库,运行python setup.py install安装时报错
-
报错内容:
descriptor.h(39): error C2371: “int8_t”: 重定义;不同的基类型 -
解决2:对代码库中所有.h文件中
typedef __int8 int8_t;全部注释掉#ifndef _MSC_VER #include <stdint.h> #else // typedef __int8 int8_t; typedef __int16 int16_t; typedef __int32 int32_t; typedef __int64 int64_t; typedef unsigned __int8 uint8_t; typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; #endif -
原因2:问题出在
int8_t类型的重定义。这是因为在代码中可能同时包含了多个定义int8_t的头文件,导致编译器报错。
报错3:修改.h文件的int8_t 部分后,继续报错
src/pyelas.cpp(342): error C7556: 不能将指定初始值设定项与非指定初始值设定项混合
error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.37.32822\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
-
解决3:替换
src/pyelas.cpp的在约341行的结构体代码-
原代码
PyTypeObject ElasType = { PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "elas.Elas", .tp_basicsize = sizeof(ElasObject), .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_doc = "The main Elas class", .tp_methods = Elas_methods, .tp_members = Elas_members, .tp_init = reinterpret_cast<initproc>(Elas_init), .tp_new = Elas_new, }; -
替换代码
PyTypeObject ElasType = { .ob_base = {0}, .tp_name = "elas.Elas", .tp_basicsize = sizeof(ElasObject), .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_doc = "The main Elas class", .tp_methods = Elas_methods, .tp_members = Elas_members, .tp_init = reinterpret_cast<initproc>(Elas_init), .tp_new = Elas_new, };
-
-
原因3:问题出在初始化列表中混合了指定成员初始化和非指定成员初始化。在C语言中,初始化结构体时,不能混合使用指定成员初始化(如
.tp_name = "elas.Elas")和非指定成员初始化(如直接赋值PyVarObject_HEAD_INIT(NULL, 0))。这种混合使用是C语言标准所不允许的。
浙公网安备 33010602011771号