【问题标题】:Using numpy on an embedded python interpreter using VS2008 under Windows 7在 Windows 7 下使用 VS2008 在嵌入式 python 解释器上使用 numpy
【发布时间】:2014-08-24 06:28:01
【问题描述】:

让我们来看看我的项目。

我正在使用 Visual Studio 2008、Python 2.7 和 numpy 1.8.1(但我尝试了多个版本,但都没有工作)。我的项目正在调试模式下编译。

这是一个非常简单的代码:

/* = Main.cpp file = */
#include "stdafx.h"
#include "Python.h"

int _tmain(int argc, _TCHAR* argv[])
{
    PyObject *pName, *main;
    Py_Initialize();

    pName = PyUnicode_FromString("main");
    main = PyImport_Import(pName);

    Py_XDECREF(pName);

    if (main != NULL) 
    {
        printf("Python Module Loaded!!\n");
    }
    else  
    {
        printf("Unable to load Python Module!!\n");
    }
    return 0;
}

""" = Main.py file = """
print 'Hello World!'

如果我执行这段代码,我会得到:

正如预期的那样。

我将 main.py 更改为:

""" = Main.py file = """
import numpy
print 'Hello World!'

然后我得到:

我尝试在 python 解释器上单独运行 main.py(不将其嵌入到 C++ 中),然后一切正常:

我也尝试过对main.cpp进行如下修改:

#include "stdafx.h"
#include "Python.h"

int _tmain(int argc, _TCHAR* argv[])
{
    PyObject *pName, *main;
    Py_Initialize();

    PyRun_SimpleString("import numpy");

    return 0;
}

从这段代码的输出是:

最后我也尝试在发布模式下编译原始版本的 main.cpp 代码,然后输出是:

所以,我的问题是:我可以做些什么来让 numpy 在 Visual Studio 2008 上使用嵌入式解释器在调试编译下工作?

【问题讨论】:

    标签: c++ python-2.7 visual-studio-2008 numpy windows-7


    【解决方案1】:

    您知道您必须使用构建的 python 调试版本,不是吗?那可能是你的问题。 (我会发表评论但没有代表):)

    【讨论】:

      猜你喜欢
      • 2012-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多