Python Embedding in C++

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Python Embedding in C++

    Hallo,
    wie der Titel sagt hab ich vor Python in C++ (Konsolen-Anwendung) einzubinden (wenn man das so überstetzen kann). Also leg ich mir einfach C++-Projekt an und wie im Tutorial (python.org/doc/ext/embedding.html) inkludiere ich die Python.h (aus dem python-include-ordner c:\python25\include) wiefolgt:

    Quellcode

    1. #include "stdafx.h"
    2. #include "c:\python25\include\Python.h"
    3. int _tmain(int argc, _TCHAR* argv[])
    4. {
    5. Py_Initialize();
    6. PyRun_SimpleString("print \"hallo\"");
    7. Py_Finalize();
    8. return 0;
    9. }


    Und dann kommt da der Fehler:
    c:\dokumente und einstellungen\codework\eigene dateien\visual studio 2005\projects\python\python\pyconfig.h(189) : fatal error C1083: Datei (Include) kann nicht geöffnet werden: "basetsd.h": No such file or directory
    Es ist nich schwer zu erraten was da falsch läuft. Nur wo bekomm ich die Header-Datei her?

    Es wär cool wenn mir jemand sagen kann wieso die Datei nicht existiert und vielleicht auch wo ich die her krieg...

    Danke im Vorraus.


    PS: Ich benutzte VC++ 2005 EE. Und geGoog'elt hab ich schon.
  • Hab was gefunden *gg* [google]site:python.org basetsd.h "No such file or directory "[/google]

    > mail.python.org/pipermail/python-win32/2006-June/004737.html
    I've only skimmed your post briefly, but this is likely your problem. Python extensions cannot be built with Visual C++ 2005 (incompatible C runtime), so this doesn't work. You need the Visual C++ Toolkit Edition, but MS no longer seem to supply this :( If you can get someone who has a copy to send it to you, that would be one option - but it's a 32MB file, and I don't know the redistribution conditions, it's probably not allowed, so you may have problems there).

    The other option is to install Mingw (from www.mingw.org), and build using setup.py build --compiler=mingw32. This works fine, unless your extension code uses MSVC specific extensions. The instructions in the Python docs are a little out of date, I believe. With Python 2.4, you shouldn't need to do anything more than install mingw, make sure gcc is on your path, and run setup.py as above. You can even edit the distutils config file (I can't remember its location offhand, sorry) to specify that distutils should use mingw by default.
  • Also wieder dieses blöde Microsoft....

    Wenn ich das richtig verstehe Unterstützt der VC++ Compiler (2k5EE) Python Embedding nicht(?), aus welchem Grund auch immer.

    Gibt's denn einen guten C++-Editor + Compiler (also wo man nich immer alles selbst compilieren muss)? Borland C++, vielleicht?

    Schön'n dank an den der ein hat...!

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von neckcracker ()

  • Ich verstehe die Python-Usergroup-Diskussion nicht so ganz. Einen Beitrag weiter wird ihm VisualStudio empfohlen:
    mail.python.org/pipermail/python-win32/2006-June/004739.html

    I would recommend buying Visual Studio. It's what python 2.4 is built
    with, and it makes compiling extensions nice and easy.


    Wobei VisualStudio doch nur eine IDE ist, oder? Der Compiler müsste doch eigentlich der selbe sein.
    Ich hab zwar auch mal damit gearbeitet, aber mich nie in die Menüs verirrt.

    Ich glaube die beste Lösung ist Eclipse mit CDT Plugin als IDE und minigw oder GCC als Compiler.
  • Ich würde bei der EE mal spontan auf das Platform SDK tippen, könnteste versuchen das zu installieren und schauen ob das dann geht.

    Alternativ würde ich Code::Blocks Eclipse/CDT vorziehen, ist einfach ein deutlicher Geschwindigkeitsunterschied bei der CodeCompletion.

    MinGW musst du fast immer separat herunterladen, aber der Installer macht daffür dann genau das was du willst und das einfach ;) Und bei Code::Blocks nimmst du dann einen Nightly, die Links gibts im Forum (nicht zu verfehlen), das sind dann 2 weitere Archive, die du noch entpacken musst ...
    There are only 10 types of people in the world: Those who understand binary, and those who don't.

    Download meines ersten Spiels:HIER
    Über Feedback würde ich mich freuen ;)
  • Jaja. Aber ich habs jetzt mit Cygwin probiert. Aber da kommt dann das hier:
    pythonembed.cpp: undefined reference to '_Py_Initialize'
    pythonembed.cpp: undefined reference to '_Py_SimpleStringFlags'
    pythonembed.cpp: undefined reference to '_Py_Finalize'
    Hier nochma der Quellcode:

    Quellcode

    1. #include "py25/Python.h"
    2. int main(int argc, char *argv[])
    3. {
    4. Py_Initialize();
    5. PyRun_SimpleString("print \"hallo dude\"");
    6. Py_Finalize();
    7. return 0;
    8. }
  • CygWin ist meiner Meinung nach sogesehen ungünstg, dass es die eigene Runtime - dll braucht und dadurch GPL-Zwang besteht - für einen ersucht tut's aber allemal ;)

    Bist du dir sicher, dass du für Python keine lib mitlinken musst?
    There are only 10 types of people in the world: Those who understand binary, and those who don't.

    Download meines ersten Spiels:HIER
    Über Feedback würde ich mich freuen ;)
  • Ich hab nochmal nachgesehen die Bibliotek (libpython25.a) sollte die Richtige sein ;)

    ->

    Quellcode

    1. g++ SOURCEFILE -o AUSGABEDATEI -LC:\Python25/libs -lpython25


    sollte gehen.

    Immer noch ungetestet ;)
    There are only 10 types of people in the world: Those who understand binary, and those who don't.

    Download meines ersten Spiels:HIER
    Über Feedback würde ich mich freuen ;)
  • Hm, dein Command war nich ganz richtig... Zwischen dem -L und dem C:\... muss ein Leerzeichen sein. Wahrscheinlich ein Flüchtigkeitsfehler.

    So:

    Quellcode

    1. g++ pythonembed.py -o pythonembed.exe -L C:/Python25/libs -lpython25


    Ich denke ma das Problem is gelöst denn jetzt kommt kein "Undefined... Undeclared..." oder so, jetzte gibts bei den Include-Datein Fehler in intobject.h und longobject.h

    intobject.h (44): error '__int64' does not have a name type
    longobject.h (43): error '__int64' was not declared in this scope
    longobject.h (45): error '__int64' does not have a name type
    longobject.h (46): error '__int64' does not have a name type
    longobject.h (47): error '__int64' does not have a name type
    Tja, das is dann wohl dumm das die Header Fehler haben?!

    Also hab ich hab das ganze auch mit dem Lib-Path von Cygwin (ich hab mit cygwin auch python installiert) c:/cygwin/libs probiert: Funktioniert auch nicht.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von neckcracker ()