Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.062 Beiträge
 
Delphi 10.4 Sydney
 
#8

AW: Python im Delphi ausführen (geht nicht)

  Alt 22. Jan 2021, 07:39
Nur vom reinen Doku lesen sind mir die folgenden Punkte aufgefallen.
Ich habe sie im Quelltextschnipsel ergänzt und mit Kommentar versehen.
https://github.com/pyscripter/python.../FindingPython

Zitat:
If you want to use a specific unregistered version set the following properties
DLLName e.g. python38.dll
RegVersion e.g 3.8
Set UseLastKnownVerion property to False
Set the DLLPath to the path where the DLL is located
Set the AutoLoad property to False
In your FormCreate event handler of the MainForm or in another suitable place run the following assuming that PythonEngine is the name of the component
PythonEngine.SetPythonHome('your python installation directory')
PythonEngine.LoadDLL
Delphi-Quellcode:
procedure TForm9.BtExecClick(Sender: TObject);
begin
  if not PythonEngine1.IsHandleValid then begin
    PythonEngine1.DllPath := EdDllPath.Text; // hier ist die Bitness sichergestellt? Manchmal hat man ja Tomaten auf den Augen und versucht stundenlang eine 64-Bit DLL in einem 32-Bit Prozess zu laden
    PythonEngine1.DllName := EdDllName.Text;
    PythonEngine1.RegVersion := ''; // fehlt, da muss sowas wie 3.9 rein
    PythonEngine1.UseLastKnownVersion := False;
    PythonEngine1.AutoLoad := False // hat gefehlt
    PythonEngine1.SetPythonHome('your python installation directory'); // hat gefehlt (ggf. Inhalt aus PythonEngine1.DllPath probieren)
    MaskFPUExceptions(True); // hat gefehlt, vielleicht hilfreich
    PythonEngine1.LoadDll;
  end;

  if not PythonEngine1.Initialized then begin
    PythonEngine1.InitScript.Text := EdGlobalScript.Text;
    PythonEngine1.Initialize;
  end;
...
end;

Geändert von TiGü (22. Jan 2021 um 07:42 Uhr)
  Mit Zitat antworten Zitat