In Python kann keine benutzerdefinierte DLL importiert werden

Ich versuche, eine C ++ - Klasse mit @ Python verfügbar zu machboost::python, also gehe ich durchdieses Tutorial. Ich habe ein visuelles Studio erstellt.dll project, mit diesem Quellcode:

#include <boost/python.hpp>
using namespace boost::python;

struct World
{
    void set(std::string msg) { this->msg = msg; }
    std::string greet() { return msg; }
    std::string msg;
};

BOOST_PYTHON_MODULE(hello)
{
    class_<World>("World")
        .def("greet", &World::greet)
        .def("set", &World::set)
    ;
}

Und ich habe es als 64-Bit-DLL erstellt. Der nächste Schritt im Tutorial lautet:

Hier haben wir einen C ++ - Klassenwrapper geschrieben, der die Memberfunktionen greet und set verfügbar macht. Nachdem wir unser Modul als gemeinsam genutzte Bibliothek erstellt haben, können wir unsere Klassenwelt in Python verwenden. Hier ist eine Python-Beispielsitzung:

>>> import hello
>>> planet = hello.World()
>>> planet.set('howdy')
>>> planet.greet()
'howdy'

Nach dem Start von python im selben Verzeichnis und der Eingabe vonimport hello Ich bekomm

>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'hello'
>>>

Ich habe versucht, die 'dll'-Dateien in @ umzubenennhello.dll und auch kopierenjede Ausgabedatei dll, exp, ilk, lib, undpdb) bis%PYTHONPATH%\DLLs, dennoch kann ich das Modul nicht in Python importieren.

Viel googeln brachte mich zuDieser Artike empfehle ich benutzectypes um das @ zu importierdll. Dadurch kann ich das @ laddll, aber ich kann die "World" -Klasse immer noch nicht anrufen. Beispielsweise

>>> import ctypes
>>> mydll = ctypes.cdll.LoadLibrary("hello")
>>> mydll
<CDLL 'hello', handle 7fef40a0000 at 0x775ba8>
>>> hello = mydll.World()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python35\lib\ctypes\__init__.py", line 360, in __getatt
r__
    func = self.__getitem__(name)
  File "C:\Program Files\Python35\lib\ctypes\__init__.py", line 365, in __getite
m__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'World' not found
>>>

So ein paar Fragen:

Ist es möglich ein @ zu importierdll in Pythonohn mit ctypes? Das Tutorial scheint darauf hinzudeuten, bietet aber nicht viele Details über den richtigen Weg, um die DLL in Python zu bekommen.

Welche Dateien brauche ich und wo? Es scheint, als sollte ich nur das @ brauchdll Datei von Visual Studio im Arbeitsverzeichnis meiner Python-Shell, aber das funktioniert bei mir eindeutig nicht.

Warum kann ich nicht anrufenWorld durch ctypes?

Einige wichtigere Details: Ich verwende Windows 7 64-Bit, Python 3.5.2 64-Bit und Visual Studio 2015 mit Boost 1.61.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage