【问题标题】:Cannot build project which is using Python无法构建使用 Python 的项目
【发布时间】:2018-06-29 10:27:33
【问题描述】:

我正在尝试在我的 Visual C++ 项目中使用 https://github.com/lava/matplotlib-cpp
我添加了库

Python36-32\libs\python36_d.lib
Python36-32\libs\python3_d.lib

但我仍然收到错误

错误 LNK2019:未解析的外部符号 __imp_PyObject_GetAttrString 在函数“private: __cdecl matplotlibcpp::detail::_interpreter::_interpreter(void)”中引用 (??0_interpreter@detail@matplotlibcpp@@AEAA@XZ) 错误 LNK2019:未解析的外部符号 __imp__Py_NegativeRefcount 在函数“bool __cdecl matplotlibcpp::plot(class std::vector > const &,class std::vector > const &,class std::basic_string,class std::allocator > const & )" (??$plot@NN@matplotlibcpp@@YA_NAEBV?$vector@NV?$allocator@N@std@@@std@@0AEBV?$basic_string@DU?$char_traits@D@std@@V?$分配器@D@2@@2@@Z) 错误 LNK2019:未解析的外部符号 __imp__Py_Dealloc 在函数“bool __cdecl matplotlibcpp::plot(class std::vector > const &,class std::vector > const &,class std::basic_string,class std::allocator > const & )" (??$plot@NN@matplotlibcpp@@YA_NAEBV?$vector@NV?$allocator@N@std@@@std@@0AEBV?$basic_string@DU?$char_traits@D@std@@V?$分配器@D@2@@2@@Z) ...

我还需要补充什么?


现在可以构建了。我不知道发生了什么。现在我在这个地方遇到运行时错误

    PyObject* matplotlibname = PyString_FromString("matplotlib");
    PyObject* pyplotname = PyString_FromString("matplotlib.pyplot");
    PyObject* pylabname  = PyString_FromString("pylab");
    if (!pyplotname || !pylabname || !matplotlibname) {
        throw std::runtime_error("couldnt create string");
    }

PyErr_Print()给了

ImportError: numpy.core.multiarray 导入失败

【问题讨论】:

    标签: python c++ visual-studio visual-c++ unresolved-external


    【解决方案1】:

    也许你的系统中没有安装 numpy 库。选择安装了 Python 解释器的 Python 环境,然后从 Overview 向下滚动到 pip。输入“numpy”并安装它。另一个选择是卸载 python 并安装 Anaconda,它默认包含 numpy 库。

    【讨论】:

      【解决方案2】:

      我在使用调试模式时遇到了类似的问题。

      解决此问题的一种方法是在使用 python.exe -m pip install matplotlib 安装 numpy 并使用库 python36.lib 之后以发布模式构建它。

      【讨论】:

        猜你喜欢
        • 2013-06-13
        • 2018-03-07
        • 2015-08-21
        • 1970-01-01
        • 1970-01-01
        • 2013-02-24
        • 2016-02-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多