首页 > 解决方案 > 找到正确的 python4delphi Tpythonengine 参数

问题描述

从这里python 4 delphi使用 Tpythonengine 时,由于这些计算机上的 python 配置不同,我无法让我的代码 *.exe 在不同的系统上运行。按照 示例代码的思路,我通过一个*.ini文件,完成了所有python4delphi-TpythonEngine参数的设置。

只有一个在 WINDOWS 操作系统上设置 python4Delphi 的教程(在 WINDOWS 下配置 ,但不适用于 LINUX。

有人可以帮助为最新的 UBUNTU、CENTOS、LINUX MX 发行版提供正确的参数。

最重要的代码部分在这里

    FPythonEngine := TPythonEngine.Create(nil);
      FPythonDelphiVar := TPythonDelphiVar.Create(nil);
      try
        FPythonEngineConfig.SetPythonengineValues(FPythonEngine);
        FPythonEngine.IO := PythonGUIInputOutput;
        FPythonDelphiVar.VarName := 'Properties';
        FPythonDelphiVar.Module := '__main__';
        FPythonDelphiVar.OnExtGetData := PropertiesExtGetData;
        FPythonDelphiVar.OnExtSetData := PropertiesExtSetData;
        FPythonDelphiVar.OnChange := PropertiesChange;
        FPythonDelphiVar.Engine := FPythonEngine;
        FPythonEngine.Loaddll;



and  the transfer of the in ini -file parameters  to the Tpythonengine 

procedure TPythonEngineConfig.SetPythonengineValues(PythonEngine
  : TPythonEngine);
var
  FPyVersions: TPythonVersions;
begin
  ///
  /// convert this  https://github.com/pyscripter/python4delphi/wiki/FindingPython
  /// into a small  automatic setting  of parameter
  ///
  PythonEngine.UseLastKnownVersion := Self.UseLastKnownVersion;
  if Self.UseLastKnownVersion then
  begin
{$IFDEF  MSWINDOWS}
    FPyVersions := GetRegisteredPythonVersions;
    FPyVersions[0].AssignTo(PythonEngine);
{$ENDIF}
{$IFDEF  LINUX}
    ///  not supported on LINUX
    ///  https://en.delphipraxis.net/topic/4700-getregisteredpythonversions-for-linux/
{$ENDIF}
  end
  else
  begin
    PythonEngine.APIVersion := self.APIVersion ;
    PythonEngine.DllName := Self.DllName;
    PythonEngine.DllPath := Self.DllPath;
    PythonEngine.AutoFinalize := Self.AutoFinalize;
    PythonEngine.AutoLoad := Self.AutoLoad;
    PythonEngine.AutoUnload := Self.AutoUnload;
    PythonEngine.RedirectIO := Self.RedirectIO;
    PythonEngine.UseWindowsConsole := Self.UseWindowsConsole;
    PythonEngine.RegVersion := Self.RegVersion;
  end;
end;

标签: pythonubuntudelphipython4delphi

解决方案


推荐阅读