Failed to import pyd File When python embed into C++

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Failed to import pyd File When python embed into C++

This post has NOT been accepted by the mailing list yet.

I create a pyd File named "testPyd" with boostPython,and then I import the testPyd module into "", it works perfect!
But when I embeded the python interpreter into my C++ project and run the "", it comes out a "ImportErr: no module named testPyd".
It has confused me for two days and I googled for long time,but I can't find the answer!
Anybody here can help me ?
Thank you!

Here is my test examples:
The C++ codes to build the *pyd File* is:

#ifndef EXCUTE_H_
#define EXCUTE_H_
#include <string> 

class Excute
        int getIoReuslt(std::string ioStr);
        int getSignal();

#include "Excute.h"
#include "Explanation.h"
#include <boost/python.hpp> 

int Excute::getIoReuslt(std::string ioStr)
        return 1;

int Excute::getSignal()
        int i = rand()%2;
        return i;

        using namespace boost::python;
        class_<Excute>("Excute", init<>())
                .def("getIoResult", &Excute::getIoReuslt)
                .def("getSignal", &Excute::getSignal)
Then a pyd File Named pythonDll is created(pythonDll.pyd),
Here are the codes in my

from pythonDll import*
print h.getIoResult("a")
print h.getSignal()

And this script works perfect in IDLE.

And then I embed python into my C++ project,Here are the test codes:
#include <Python.h> 
#include <string> 

int main(int argc, char* argv[])
        FILE * fp = fopen("$PATH/", "r");
        if (fp == NULL)
            return 1;


        return 0;

The result is:
Traceback (most recent call last):
  File "<string>", line 1, in <module> 
  File "$PATH/", line 1, in <module> 
    from pythonDll import*
ImportError: No module named pythonDll
[19228 refs]