#include <Python.h>
#include <iostream>
using namespace std;
int main()
{
Py_Initialize();
if (!Py_IsInitialized())
{
printf("初始化失败!");
return 0;
}
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')");
PyRun_SimpleString("import cv2");
Py_Finalize();
}
opencv-python版本4.8.0.76
解决方法:
卸载opencv-contrib-python
pip uninstall opencv-contrib-python
补充解决方法:
运行时将python38.dll和python3.dll都复制到exe同目录或者工程目录,我的python版本是3.8.5