C++调用python函数问题记录
问题1
# gm => excel
def export(gm, excel, select, unit, hide):
ret = read_gm(gm)
data = ret[0]
channels = ret[1]
msg = ret[2]
if msg == 'ok':
msg = write_excel(data, channels, excel, select, unit, hide)
if msg == 'ok':
os.system(f'"{excelfilepath}"')
return msg
msg = export(gmfilepath, excelfilepath, exportselect, resistanceunit, hidecolumn)
print(msg)

分析:PyImport_ImportModule会调用最底下的代码,而export调用的传入参数未被初始化,故报错。
问题2
# gm => excel
def export(gm, excel, select, unit, hide):
ret = read_gm(gm)
data = ret[0]
channels = ret[1]
msg = ret[2]
if msg == 'ok':
msg = write_excel(data, channels, excel, select, unit, hide)
if msg == 'ok':
os.system(f'"{excelfilepath}"')
return msg

分析:和问题1类似,excelfilepath未初始化。
问题3
如果 exe 目录下有 python311.dll,系统 Path 路径里又有 python,调用会失败。
- 去掉 exe 目录下的 python311.dll;或
- 用 Py_SetPythonHome 设置好 python 的执行文件夹。
posted on 2024-04-29 10:24 OctoberKey 阅读(21) 评论(0) 收藏 举报
浙公网安备 33010602011771号