注册 登录
编程论坛 Python论坛

windows下Python调用Python出现error LNK2019

小鑫小 发布于 2016-03-15 15:02, 4649 次点击
无法解析的外部符号 _PyCallable_Check,该符号在函数 _main 中被引用    等一些有关Python的函数都无法解析;
一下是我写的代码
#include<iostream>
#include<Python.h>
#include <codecvt>
using namespace std;
int main()
{
    Py_Initialize();
    if (!Py_IsInitialized())
    {
        return -1;
    }
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("sys.patth.append('.\')");

    PyObject *pName, *pModule, *pDict, *pFunc;
    wstring str = L"statistic_word";
    wstring_convert<codecvt_utf8<wchar_t>> conv;
    string sr = conv.to_bytes(str);

    pName = PyUnicode_FromUnicode(str.c_str(),str.size());
    pModule = PyImport_ImportModule(sr.c_str());

    if (!pModule)
    {
        cout << "can't find statistic_word.py" << endl;
        return -1;
    }

    pDict = PyModule_GetDict(pModule);
    if (pDict)
    {
        return -1;
        
    }
    pFunc = PyDict_GetItemString(pDict,"cut_word");
    if (!pFunc || !PyCallable_Check(pFunc))
    {
        cout << "can;t find function [cut_word]" << endl;
        return -1;
    }
    PyEval_CallObject(pFunc,NULL);
    Py_Finalize();
    system("pause");
    return 0;
}
0 回复
1